Updating object using state Flashcards

1
Q

Treat all state in React as immutable.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When you store objects in state

A

mutating them will not trigger renders and will change the state in previous render “snapshots”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Instead of mutating an object

A

create a new version of it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

You can use the {…obj

A

something: ‘newValue’} object spread syntax to create copies of objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Spread syntax is shallow: it only copies one level deep.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

To update a nested object

A

you need to create copies all the way up from the place you’re updating.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

To reduce repetitive copying code

A

use Immer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly