I'm trying to understand why es6 object spread behaviour is different between objects and when it's used in React components to spread props.
The following makes sense to me:
const a = {
a:1,
b:2
}
const c = {...a}
Now variable c will have the same properties as variable 'a' with key value pairs in this format of a:1, b:2.
This doesn't make sense:
<Mycomponent {...a} />
turns the props into "a={1} b={2}"
. Why does it behave in this way instead of the usual way which is key value pairs a:1, b:2
?
I would like to understand why this works like this so I can better understand the language.
I've seen tutorials and articles which explain how spread works in both cases but I haven't found an answer why it spreads differently?