In base allo react docs, se un componente ha più figli, questo.proprio.children dovrebbe essere un array.Oggetti di reazione.children non è array
ho le seguenti componenti:
export class Two extends React.Component {
componentDidMount() {
console.log(Array.isArray(this.props.children)); // false
}
render() {
return(
<div>
{this.props.children}
</div>
);
}
};
Quale passo i bambini al metodo render() di un altro componente:
<Two>
<Img src="/photos/tomato.jpg"/>
<Img src="/photos/tomato.jpg"/>
</Two>
Perché this.props.children non è un array? Ancora più importante, come posso averne uno?
secondo anche al [documenti] (https://facebook.github.io/react/docs/top-level -api.html # react.children), i bambini sono una struttura di dati opaca. –
Cosa devi fare con 'this.props.children'? Se vuoi iterare tutti i bambini di quanti hai strumenti come in [Utilità React Children] (https://facebook.github.io/react/docs/top-level-api.html#react.children). –
Forse perché Img è in maiuscolo? –