Updating object using state Flashcards
1
Q
Treat all state in React as immutable.
A
2
Q
When you store objects in state
A
mutating them will not trigger renders and will change the state in previous render “snapshots”.
3
Q
Instead of mutating an object
A
create a new version of it
4
Q
You can use the {…obj
A
something: ‘newValue’} object spread syntax to create copies of objects.
5
Q
Spread syntax is shallow: it only copies one level deep.
A
6
Q
To update a nested object
A
you need to create copies all the way up from the place you’re updating.
7
Q
To reduce repetitive copying code
A
use Immer.