Skip to main content

How does local state differ from global state?

Local state is data needed only by one component. Global state is data that is used in multiple places across the application and must be shared.


Local state:

  • Lives inside the component (this.counter = 0)
  • Does not affect other parts of the application
  • Resets when the component is destroyed
  • Convenient for small things: modals, flags, temporary values

Example: A "show password" flag in an input is purely local state.


Global state:

  • Stored in services, stores (NgRx, Akita)
  • Accessible from different components
  • Lives as long as the application does
  • Used to manage user data, settings, authentication, and so on

Example: The current user's data, the cart, catalog filters, the interface language.


Conclusion: Local is about "here and now", global is about "everyone knows it, always". The bigger the application, the more important it is to keep them clearly separated.

Short Answer

Interview ready
Premium

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