Skip to main content

Spreading

JavaScript spread syntax (...) is a surprisingly powerful construct. It has two main use cases in our applications:

Shallow copying

Spreading creates new instances of objects or array, but we need to be very careful because it only does a shallow copy. If you have a deeply nested object or array, nested entities will still hold a reference to an original value and hence dangerous bugs can occur.

Copying is needed when doing state changes (either local or state management e.g. Redux).

Live Editor
Result
Loading...

Populating jsx attributes

Live Editor
Result
Loading...