Global State / Store
Shared state that any component can subscribe to and update through the store's own API, however deep in the tree it sits.
See it
What it is
A store is shared state with two things bolted on: subscriptions, so a component re-renders when the slice it reads changes, and an explicit update API, so writes go through something you can name and test rather than anyone assigning to a variable. Where it physically sits and what shape it takes vary by tool: Redux and Zustand keep one object outside the component tree, Jotai and Recoil spread many small atoms, Context plus useReducer lives inside the tree. What they share is that a component twelve levels deep can read and update a fact without anyone threading it down. It exists for facts that distant, unrelated parts of the app both need: the session, the theme, the cart, whether the command palette is open. Canonical names beyond the ones above: Redux Toolkit, MobX, Pinia for Vue, Svelte stores.
Reach for one when two components need the same fact and have no useful common parent, or when the update rules are worth writing down in one testable place (that's what Redux actions and reducers buy you). If a single shared parent would do the job, use the parent.
Two traps. First, global is not free: subscribing to the whole store re-renders a component on every unrelated change, so always select narrow slices. Second, a store is a bad cache. Park fetched API data in it and you have quietly signed up to hand-write staleness, refetching, deduping, and invalidation that a query library already does.
Ask AI for it
Create a global store for this app with Zustand: one typed store with slices for session, theme, and cart, each slice keeping its actions next to the state they change. Export narrow selector hooks (useCartCount, useTheme) so components subscribe to a single field instead of the whole store. Keep server-fetched data out of the store entirely, persist only the theme slice to localStorage, and give me the TypeScript types plus one example component reading and writing.