open-context open-context
November 9, 2026 · 6 min read

Why open-context Uses React Context Instead of Redux

open-context's web UI holds its entire state tree — user preferences, imported conversations, and conversion pipeline progress — in a single React Context paired with useReducer, defined in one file: ui/src/store/context.tsx. There is no Redux, Zustand, Jotai, Recoil, or MobX installed anywhere in open-context's UI. The reason is ordinary: the app has one global state tree with a small, fixed set of actions — exactly the shape React's built-in tools were designed to handle.

Key takeaways

  • ui/package.json lists no Redux, Zustand, Jotai, Recoil, or MobX dependency — state management is 100% built-in React.
  • The entire app state (preferences, conversations, pipeline) lives in one AppContext, dispatched through a single appReducer with nine action types.
  • Preferences load from the server on mount and auto-save back with an 800ms debounce — logic that lives in the same provider file, not a separate middleware layer.
  • React's own documentation frames reducer-plus-context as the built-in scaling pattern for exactly this case: one component's state logic, shared down an unrelated subtree.
  • A dedicated library earns its cost when an app has many independent state slices, heavy cross-cutting async logic, or needs time-travel debugging — none of which open-context's UI currently has.

The question every React project eventually gets asked

Any time a React app passes a handful of hooks around, someone asks "shouldn't this be in Redux?" It's a fair question — Redux, Zustand, and similar libraries solve real problems around selective re-rendering, middleware, and devtools. But the right test isn't whether a library is popular. It's whether your app's state actually has the shape those libraries were built for: many independent slices, heavy async orchestration, or dozens of components that each need to subscribe to a different narrow piece of a large store.

What open-context's UI actually needs to track

Per the project's own state-shape contract, open-context's UI tracks exactly three things: preferences (the full UserPreferences tree), conversations (the imported NormalizedConversation[] list), and pipeline (conversion progress). A small, known set of components read and write that state — the Preferences Editor, the Dashboard, the Conversation Viewer, the Conversion Pipeline view, and the Vendor Export page. That's one app-wide tree shared by a handful of screens, not several independently-scaling domains that would benefit from selector-based subscriptions.

Inside ui/src/store/context.tsx

One reducer, nine actions

The whole store is a single appReducer switch statement handling nine action types: PREFS_LOADED, SET_PREFERENCES, UPDATE_PREFERENCES, SET_CONVERSATIONS, TOGGLE_CONVERSATION, UPDATE_CONVERSATION, DELETE_CONVERSATION, SET_PIPELINE, and RESET_PIPELINE. Each case is a plain object spread that returns a new state slice — no middleware, no thunks, no sagas.

type AppAction =
  | { type: 'PREFS_LOADED'; payload: UserPreferences }
  | { type: 'SET_PREFERENCES'; payload: UserPreferences }
  | { type: 'UPDATE_PREFERENCES'; payload: Partial<UserPreferences> }
  | { type: 'SET_CONVERSATIONS'; payload: NormalizedConversation[] }
  | { type: 'TOGGLE_CONVERSATION'; payload: string }
  | { type: 'UPDATE_CONVERSATION'; payload: { id: string; updates: Partial<NormalizedConversation> } }
  | { type: 'DELETE_CONVERSATION'; payload: string }
  | { type: 'SET_PIPELINE'; payload: Partial<PipelineState> }
  | { type: 'RESET_PIPELINE' };

Load once, save on a debounce

On mount, AppProvider fetches /api/preferences and dispatches PREFS_LOADED. A second effect watches state.preferences and calls scheduleSave, which clears any pending timer and re-arms an 800ms debounced PUT back to /api/preferences — so rapid edits in the Preferences Editor don't fire a network request on every keystroke. useAppState() is the single hook every component calls to read state or get a dispatch reference, and it throws if called outside AppProvider — catching a whole class of "forgot to wrap it" bugs at the first render instead of silently returning stale or undefined state.

Where Context actually gets expensive

It's worth being honest about the real tradeoff here: Context has no built-in selector mechanism, so every dispatch re-renders every component that calls useAppState() — unlike Redux with reselect, or Zustand's selector functions, which only re-render components reading the exact slice that changed. That's a legitimate cost in a large app with dozens of independently-updating widgets.

It doesn't show up here because the state tree is small and the consuming component count is in the single digits. Nothing in the UI re-renders on every keystroke except the form inputs that are already re-rendering themselves as controlled inputs. If open-context's UI grew into something with many independently-updating widgets, that calculus would change — and the project would reach for selector-based state at that point, not before.

What React's own documentation says to do first

React's guide on scaling up with reducer and context describes combining useReducer with Context as the built-in way to let one component's state logic be read deep in the tree without prop drilling — framed explicitly as a scaling step, not a last resort you reach for only after outgrowing a library. The companion guide on passing data deeply with context is equally direct about when Context fits: it's for data genuinely needed by many components at different nesting levels, not a shortcut around passing a couple of props through one intermediate component. open-context's UI state — preferences, conversations, pipeline — is read by components at very different depths of the tree, which is exactly the case Context is meant for.

When this project would reach for something else

The threshold is concrete, not hand-wavy. If open-context's UI added real-time multi-user collaboration, a large number of independently polling data sources, or state logic that needed middleware — logging, undo/redo, websocket sync — a purpose-built library would be the right call: Zustand for a lighter selector-based store, or Redux Toolkit for the full ecosystem of devtools, middleware, and RTK Query. The Preferences Editor, with its six independent sections, is the component most likely to grow in that direction first if open-context ever adds live collaborative editing.

For a local-first, single-user tool, that threshold hasn't been crossed. The line in this project's own contributor guide — "State: React Context + useReducer (no Redux/Zustand)" — is a deliberate choice recorded for future contributors, not an oversight waiting to be fixed.

See the preferences and pipeline state in action.

Try open-context →

FAQ

Does open-context's UI use Redux anywhere?

No. ui/package.json has no Redux, Zustand, Jotai, Recoil, or MobX dependency. All UI state lives in one React Context backed by useReducer, defined in ui/src/store/context.tsx.

Isn't React Context bad for performance?

Context re-renders every consumer on every update to the values it provides, which is a real limitation for large or deeply-nested trees. open-context's UI has a small, flat component tree reading one state object, so this cost hasn't shown up in practice.

What's the difference between useReducer and Context in this app?

useReducer owns the state-transition logic — nine well-defined actions like SET_PIPELINE or TOGGLE_CONVERSATION. Context is just the transport that lets components anywhere in the tree read that state and dispatch those actions without passing props down manually.

Would open-context ever switch to Redux or Zustand?

Only if the UI grew real-time collaboration, many independently-updating widgets, or state logic needing middleware like undo/redo or websocket sync. None of those exist in the current preferences, conversations, and pipeline UI.

Where does open-context's UI state get persisted?

Preferences are fetched from and saved back to the server's REST API at /api/preferences with an 800ms debounce on save. Conversations and pipeline state are session-only React state, not persisted between page loads.