Basic Concepts - monello/complete-react-guide-2024 GitHub Wiki
Rest
-operator
The {var1, var2, ...restOfProps}
Spread
-operator
The <SomeComponent {...someObject}>
const copyOfObj = {...Obj}
const copyOfArr = [...Arr]
- Spread props into a custom component
- Used to assign all the keys and values as props to a component
- Using the spread-operator to deep-copy multi-dimensional array
Cool destructuring trick, to get a copy of an object excluding certain props:
const someObject = {
propOne: 'value one',
foo: 'foo value',
propThree: 'xyz'
};
const {foo, ...newObjectExludingFoo} = someObject;
foo
is now just 'foo value'
and newObjectExcludingFoo
is now this:
{
propOne: 'value one',
propThree: 'xyz'
}