I understand how to use JSX Spread Attribute, but I would like to understand how it works.
Eg.
<TestComponent { ...{name: 'Tom', height: '1.8m'} } />
I assume the first pair of curl braces indicates whatever is enclosed are JS codes. Please correct me if I am wrong. If that is correct, then …{name: ‘Tom’, height: ‘1.8m’} is not valid JS syntax, as can be seen from this:
const props = ...{name: 'Tom', height: '1.8m' } // Syntax error, unexpected token where the 3 periods are
const props = { ...{name: 'Tom', height: '1.8m' } } // This works.
Does that mean the first pair of curly braces is actually the syntax for JS object and is passed as the props object? If that is true, then this should work but it doesn’t.
<TestComponent { name: 'Tom', height: '1.8m' } /> // Syntax Error
So, how is { …{name: ‘Tom’} } passed on as props behind the scene?
Thanks!