Redux and State Management: From Office Chaos to Predictable Architecture #
The Office Without Organization #
Imagine an office where every employee keeps their own copy of the company's customer database.
When Sarah in Sales updates a client's phone number, she tells Mark in Marketing. Mark updates his copy but forgets to tell Jennifer in Customer Service. Jennifer calls the old number. The client gets frustrated.
Meanwhile, Tom in Tech Support has a completely different version because he was on vacation when the updates happened.
This is your application without proper state management.
Components maintain their own state copies, pass data through props drilling multiple levels deep, and lose synchronization. One component updates, another doesn't know, and your application becomes unpredictable.
Now imagine the same office implements a central records system.
One database. One source of truth.
Anyone who needs information reads from it. Anyone who needs to update information submits a formal request form that gets processed by the records department. Every change is logged. You can see the entire history of what happened to any record.
This is Redux.
What Redux Actually Solves #
Before understanding Redux's internals, understand the problems it addresses in React applications:
Prop Drilling #
Passing data through five component levels to reach the component that needs it creates brittle, hard-to-maintain code.
Shared State #
When multiple components need the same data, lifting state up to a common ancestor creates unnecessary re-renders and complexity.
State Synchronization #
Keeping multiple components synchronized when they depend on the same data becomes exponentially difficult as applications grow.
Predictability #
Without structure, state updates happen anywhere, making bugs difficult to trace and reproduce.
Redux provides a single source of truth with strict rules about how state changes occur.
The Redux Architecture #
Redux operates on three fundamental principles:
Single Source of Truth The entire application state lives in one object tree within a single store.
State is Read-Only The only way to change state is to emit an action, an object describing what happened.
Changes are Made with Pure Functions Reducers are pure functions that take the previous state and an action, then return the next state.
Core Concepts Explained #
Store #
The store holds your application's state tree. Think of it as the central database in our office analogy.
import { createStore } from 'redux'; const store = createStore(reducer);
The store has several methods:
getState()– Returns the current statedispatch(action)– Triggers a state changesubscribe(listener)– Registers a callback that runs when state changes
Actions #
Actions are plain JavaScript objects that describe something that happened. They must have a type property.
const addUserAction = { type: 'ADD_USER', payload: { id: 1, name: 'John Doe', email: 'john@example.com' }}; const deleteUserAction = { type: 'DELETE_USER', payload: { id: 1 }};
Action Creators #
function addUser(user) { return { type: 'ADD_USER', payload: user };} function deleteUser(userId) { return { type: 'DELETE_USER', payload: { id: userId } };}
Reducers #
Reducers are pure functions that specify how the state changes in response to actions.
const initialState = { users: [], loading: false, error: null}; function userReducer(state = initialState, action) { switch (action.type) { case 'ADD_USER': return { ...state, users: [...state.users, action.payload] }; case 'DELETE_USER': return { ...state, users: state.users.filter( user => user.id !== action.payload.id ) }; case 'SET_LOADING': return { ...state, loading: action.payload }; case 'SET_ERROR': return { ...state, error: action.payload }; default: return state; }}
Critical rules for reducers:
- Never mutate the state directly
- Always return a new state object
- Must be pure functions
- No side effects
How Redux Works Under the Hood #
store.dispatch(addUser({ id: 1, name: 'John' }));
Flow:
- Dispatch action
- Reducer runs
- New state is stored
- Subscribers are notified
- Components re-render
Minimal Redux Implementation #
function createStore(reducer) { let state; let listeners = []; function getState() { return state; } function dispatch(action) { state = reducer(state, action); listeners.forEach(listener => listener()); return action; } function subscribe(listener) { listeners.push(listener); return function unsubscribe() { listeners = listeners.filter(l => l !== listener); }; } dispatch({ type: '@@INIT' }); return { getState, dispatch, subscribe };}
Redux with React #
import React from 'react';import { createStore } from 'redux';import { Provider, useSelector, useDispatch } from 'react-redux';
function Counter() { const count = useSelector(state => state.count); const dispatch = useDispatch(); return ( <> <p>Count: {count}</p> <button onClick={() => dispatch({ type: 'INCREMENT' })}> Increment </button> <button onClick={() => dispatch({ type: 'DECREMENT' })}> Decrement </button> </> );}
Redux Toolkit: Modern Redux #
import { configureStore, createSlice } from '@reduxjs/toolkit'; const counterSlice = createSlice({ name: 'counter', initialState: { value: 0 }, reducers: { increment: state => { state.value += 1; }, decrement: state => { state.value -= 1; }, incrementByAmount: (state, action) => { state.value += action.payload; } }});
When to Use Redux #
- Large application state
- Shared data across many components
- Complex state logic
- Time-travel debugging
- Large teams
When NOT to Use Redux #
- Simple apps
- Local UI state
- Server state (use React Query / SWR)
- Forms
- Learning React fundamentals
Conclusion #
Redux provides predictable state management through a unidirectional data flow:
- Actions describe changes
- Reducers process them
- Store holds the truth
The office analogy holds:
- Store = database
- Actions = request forms
- Reducers = processing department
Redux adds structure and complexity. Use it when the problem demands it—not by default.
Modern Redux Toolkit dramatically reduces boilerplate, making Redux still a strong, relevant solution for complex applications.
The key is understanding the fundamentals:
Immutability. Pure functions. Single source of truth.



Loading discussion...