Spread attributes
Shawn learned a lot of things about JSX but when he was reflecting on the previous steps, he came up with another question.
"Mike, as of now we are just passing two props to the App
component: headings
and changesets
. However, tomorrow these props can increase to any number. Passing them one by one would be cumbersome. Especially, when we have to pass some data from the recent changes API directly. It will be hard to a keep track of the structure of the incoming data and pass it accordingly in the props. Is there a better way?"
"Another excellent question, Shawn. True, it might be cumbersome passing a large number of attributes to the component one by one. But we can solve this using the spread
attributes."
var props = { headings: headings, changeSets: data, timestamps: timestamps }; ReactDOM.render(<App {...props } />, document.getElementById('container'));
"In this case, all the properties of object are passed as props to the App
component. We...