Skip to main content

What is shared state?

Shared state is common state that is shared between multiple components.


What this means:

When two or more components use the same data, and a change in one place must be reflected in another. For example:

  • The cart on the product page and the icon in the header
  • An authentication flag in the navbar and in the profile
  • A shared filter that affects multiple lists

Where shared state lives:

  • In a service (most often)
  • In an RxJS stream (BehaviorSubject, signal)
  • In a store (NgRx, NGXS, and so on)

Why it matters:

Without shared state, components easily "drift apart": one shows stale data, another shows fresh data. Shared state guarantees that every part of the application "looks at the same place".


Conclusion: Shared state is like a single point of truth for multiple participants. Change it in one place, and it changes everywhere.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.