Engineering Decisions · Junior · Question 5 of 12

Two sibling components on one page share a filter value: one edits it, the other shows the filtered table. Nothing else needs it. Where does the state go?

Show the answer

Correct answer: In their closest common parent, passed via props

Explanation

Lifting state to the closest common parent is enough for two siblings and keeps the data flow easy to follow. Context fits values needed by many components at different depths, such as a theme. A global store fits state shared across distant pages, and adding one for a single filter is more machinery than the task needs.

Further reading

Problem with a question

Engineering Decisions · Junior · question 5

Test yourself

Take the Engineering Decisions · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz