External Stores & Subscription Model
External stores are useful when state must be shared across many components or across non-React code. A store should expose a predictable subscription model so React can read a snapshot and update consumers when the relevant state changes.
Avoid duplicating the same data in both a store and many component states. Choose one source of truth and derive views from it.
Modern React provides APIs designed for safely subscribing to external stores, helping React coordinate updates with its rendering model.
Key Takeaways
- External stores are appropriate for shared client state with clear ownership.
- React needs a consistent snapshot/subscription contract.
- Do not create multiple competing sources of truth.