Flux is an application architecture Facebook introduced alongside React. It enforces unidirectional data flow: Views emit Actions (plain objects describing what happened), a single Dispatcher sends every action to the Stores, stores update their state and notify subscribed views, and views re-render. Because state changes only in response to actions, and only inside stores, data flow is predictable, traceable and debuggable. That fixed the cascading-update bugs of two-way-bound MVC. Redux is the best-known descendant (a single store plus pure reducers), and useReducer brings the same idea into components.
View --(user event)--> Action --> Dispatcher --> Store(s) --(change event)--> View
{ type: 'todo/added', payload: { text } }. It describes the event, not how to change state.In classic MVC with two-way binding, a model change could update a view, which updated another model, which updated another view. Facebook's notorious example was the chat unread-count badge that kept reappearing. With many bidirectional links, it was hard to know why something changed. Flux makes every change pass through one choke point with a named action.
function todosReducer(state = [], action) {
switch (action.type) {
case 'todo/added':
return [...state, { id: action.payload.id, text: action.payload.text, done: false }];
case 'todo/toggled':
return state.map(t => (t.id === action.payload ? { ...t, done: !t.done } : t));
default:
return state;
}
}
createSlice, Immer-based "mutations", RTK Query for server state).Much "global state" turned out to be server cache, now handled by TanStack Query, RTK Query, SWR or framework loaders and Server Components. For client state, teams choose between useState/useReducer + context, lighter stores (Zustand, Jotai), or Redux Toolkit for large apps that benefit from strict conventions and devtools. The one-way data flow principle remains central to React itself.
useReducer as the same idea locally.Spotted a mistake or a rights concern? Report an issue