What is the meaning of
{...this.props}
I am trying to use it like that
<div {...this.props}> Content Here </div>
It's called spread attributes and its aim is to make the passing of props easier.
Let us imagine that you have a component that accepts N number of properties. Passing these down can be tedious and unwieldy if the number grows.
<Component x={} y={} z={} />
Thus instead you do this, wrap them up in an object and use the spread notation
var props = { x: 1, y: 1, z:1 };
<Component {...props} />
which will unpack it into the props on your component, i.e., you "never" use {... props}
inside your render()
function, only when you pass the props down to another component. Use your unpacked props as normal this.props.x
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With