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) => (
all data props
+ {/* + Each of the `data` fields are spreaded as props + */} +Spread all props
all data props and d
+ +Add additional prop
+ {/* + After we spread, we also add `d` prop. + */}just a part of the props, @themre please explain ;)
-Order of props is important
+ {/* + We will replace `a` with 10 + */} +Omit certain properties
+ {/* + If you wish to omit certain fields, you need to write fields + that you wish to omit and with `...{newVariableName}` you will create a new + object with that name. In our part it's `omittedObject` name. + */} +