Lifting up state Flashcards

1
Q

Lifting up state

A

Often, several components need to reflect the same changing data. We recommend lifting the shared state up to their closest common ancestor.

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

Single source of truth

A

There should be a single “source of truth” for any data that changes in a React application. Usually, the state is first added to the component that needs it for rendering. Then, if other components also need it, you can lift it up to their closest common ancestor. Instead of trying to sync the state between different components, you should rely on the top-down data flow.

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

Lifting up state and debugging

A

Lifting state involves writing more “boilerplate” code than two-way binding approaches, but as a benefit, it takes less work to find and isolate bugs. Since any state “lives” in some component and that component alone can change it, the surface area for bugs is greatly reduced. Additionally, you can implement any custom logic to reject or transform user input.

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

Value can be derived from props or state

A

If something can be derived from either props or state, it probably shouldn’t be in the state.

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