global state
Data kept where any part of a program can read and change it, such as a module-level variable or an app-wide store.
In more detail
Global state is convenient for data truly shared across a program, but it hides where changes come from. On a server, one process handles many requests at once, so request data kept in global state can leak into another request. In user interfaces, libraries such as Redux or Zustand hold global state, and changes to it can cause wide re-renders. Passing data explicitly, or keeping it close to where it is used, avoids many of these problems.
Related terms
- AsyncLocalStorage — A Node.js class that keeps a value, such as the current request's ID, available to every function called during one asynchronous operation, without passing it as an argument.
- race condition — A bug whose outcome depends on the timing of two things happening at once.
- external store — State held outside React, in a library, a module variable or a browser API, which components subscribe to for changes.
- Zustand — A small state management library for React that keeps state in an external store and lets components subscribe to just the parts they use.
- React Context — A React feature that lets a parent component make a value available to every component below it without passing it as props.
- state colocation — Keeping state as close as possible to the components that use it, rather than high up in the tree or in global storage.
Taught in
- Routing & Middleware: Path Parsing & Async Context — Node.js Internals & Backend Services
- Props Contract: Immutability, Children, And Polymorphic Tags — React 19 & Modern Component Architecture
- Lifting State Up: Colocation, Ownership, And Data Flow — React 19 & Modern Component Architecture
- useSyncExternalStore: Tearing-Free Store Subscriptions — React 19 & Modern Component Architecture