Czy istnieje sposób w React, aby zapewnić domyślne rekwizyty do zagnieżdżonej tablicy elementów o określonym kształcie?Jak zapewnić domyślne rekwizyty dla zagnieżdżonego kształtu w React?
Biorąc pod uwagę poniższy przykład, moja pierwsza próba jest widoczna, jednak nie działa zgodnie z oczekiwaniami.
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 - ',
}],
};
W tym przykładzie byłoby oczekiwać, następujące:
// 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 - ' },
]
};