Есть ли способ в React предоставить реквизиты по умолчанию для вложенного массива элементов определенной формы?
Учитывая приведенный ниже пример, можно увидеть мою первую попытку, однако это не работает, как ожидалось.
static propTypes = {
heading: PT.string,
items: PT.arrayOf(PT.shape({
href: PT.string,
label: PT.string,
})).isRequired,
};
static defaultProps = {
heading: 'this works',
items: [{
href: '/',
label: ' - this does not - ',
}],
};
В этом примере я ожидал бы следующее:
// Given these props
const passedInProps = {
items: [{ href: 'foo' }, { href: 'bar' }]
};
// Would resolve to:
const props = {
heading: 'this works',
items: [
{ href: 'foo', label: ' - this does not - ' },
{ href: 'bar', label: ' - this does not - ' },
]
};