Andrew's Digital Garden

Lifting state up

A core React principle is 'lift state up'.

If components need to stay in sync, or keep a shared state, the answer is to lift state up to a shared location.

e.g. when creating an accordion component that can only have one item open at a time, don't store state in each item. Instead lift state up to a parent, which can track which item is open.

This avoids things getting out of sync, as well as extra coupling. A single source of truth.

[[react]] [[reactapi]]

Referred in

Lifting state up