Answer the question
In order to leave comments, you need to log in
How does spread work in JSX react?
Having difficulty understanding how the spread operator works when we pass props to a react element, that's what I mean
we have
<Modal name={props.name} age={props.age} />
//Ðквивалентно
<Modal {...props} />
Answer the question
In order to leave comments, you need to log in
Good afternoon!
"es6 spread spreads an array into arguments"
Object. An array is a special case of an object)
It is very difficult to explain in a simpler way than the words that you yourself wrote)
props is an object.
You pass it to the next component.
You can do it by name, as done in your example, you can do the destructuring first
const { name, age } = this.props;
<Modal age={age} name={name}>
<Modal props={props}>
then you will get these props in Modal, right? <Modal {...props} />
you just do the destructuring at the time of transmission (I hope this will be easier to understand)).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question