diff --git a/foomo/docs/frontend/typescript/spreading.md b/foomo/docs/frontend/typescript/spreading.md index 6f16c1a..bb8b168 100644 --- a/foomo/docs/frontend/typescript/spreading.md +++ b/foomo/docs/frontend/typescript/spreading.md @@ -2,9 +2,12 @@ JavaScript spread syntax `(...)` is a surprisingly powerful construct. It has two main use cases in our applications: -## Efficiently copying data +## Shallow copying -The most important use case for this is when you are working with your applications state. +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). ```jsx live function () { @@ -53,7 +56,7 @@ function () { ## Populating jsx attributes ```jsx live -function() { +function App() { // a simple Component, that will render all fields in props const Foo = (props) => (