It should be noted that this only works for objects. eg:
this.props = {
x: 'foo',
y: 'bar',
z: 'baz',
}
const {
x,
...allOtherProps
} = this.props
<Elem { ...allOtherProps } /> // works (allOtherProps is an object)
<Elem { ...x } /> // does not work (x is not an object)
<Elem x={ x } /> // works
source
share