React · Junior · Question 22 of 75
Two sibling components need the same data, which they can change. What should you do first?
- 1Copy the state into both components and sync them via
useEffect - ✓Correct answer: Lift the state to the common parent and pass the value and callbacks via props
- 3Add Redux right away
Explanation
Lifting state up is a basic technique: data should have a single source of truth in the closest common ancestor. Duplicating state and syncing it with effects leads to desync and extra renders. Global stores are needed when state is really used in many places in the tree.