flux, mobx, and redux are libraries for managing application state, but they follow different architectural patterns. flux is the original reference implementation of the unidirectional data flow pattern created by Facebook. redux is a popular, predictable state container inspired by Flux but with a single store and pure reducers. mobx takes a different approach by using observables to automatically track state changes and update the UI, feeling more like traditional object-oriented programming.
flux, mobx, and redux all solve the problem of managing complex state in JavaScript applications, but they work differently under the hood. Let's compare how they tackle common problems like data flow, state updates, and UI integration.
flux enforces a strict unidirectional flow using a central dispatcher.
// flux: Dispatcher and Store pattern
var Dispatcher = require('flux').Dispatcher;
var dispatcher = new Dispatcher();
var Store = require('flux').Store;
var myStore = new Store(dispatcher);
myStore.on('change', () => { /* update UI */ });
redux simplifies Flux into a single store with pure reducers.
// redux: Store and Reducer pattern
import { createStore } from 'redux';
function reducer(state = {}, action) {
if (action.type === 'ADD') return { count: state.count + 1 };
return state;
}
const store = createStore(reducer);
store.dispatch({ type: 'ADD' });
mobx uses observables to track state automatically.
// mobx: Observable and Action pattern
import { makeAutoObservable } from 'mobx';
class Counter {
count = 0;
constructor() { makeAutoObservable(this); }
increment() { this.count++; }
}
const counter = new Counter();
counter.increment();
flux requires you to define action creators and handle payloads manually.
// flux: Action Creator
var ActionCreator = {
add: function(text) {
dispatcher.dispatch({
type: 'ADD_ITEM',
text: text
});
}
};
redux requires pure functions that return new state objects.
// redux: Pure Reducer
function reducer(state = { items: [] }, action) {
switch (action.type) {
case 'ADD_ITEM':
return { items: [...state.items, action.text] };
default:
return state;
}
}
mobx allows direct mutation inside actions.
// mobx: Direct Mutation
import { action } from 'mobx';
class Store {
items = [];
addItem = action((text) => {
this.items.push(text); // Direct mutation is allowed
});
}
flux originally relied on mixins or higher-order components.
setState when stores change.// flux: Manual Subscription
class Component extends React.Component {
componentDidMount() {
this.store.addChangeListener(this.onChange);
}
onChange() {
this.setState({ data: this.store.getData() });
}
}
redux uses connect or hooks like useSelector.
react-redux handles the subscription lifecycle.// redux: React-Redux Hooks
import { useSelector, useDispatch } from 'react-redux';
function Component() {
const count = useSelector(state => state.count);
const dispatch = useDispatch();
return <button onClick={() => dispatch({ type: 'ADD' })}>{count}</button>;
}
mobx uses the observer wrapper.
// mobx: Observer Component
import { observer } from 'mobx-react';
const Component = observer(({ store }) => {
return <button onClick={() => store.addItem('New')}>{store.items.length}</button>;
});
flux has basic tooling support.
// flux: Manual Logging
dispatcher.register(function(payload) {
console.log('Dispatched:', payload);
});
redux has industry-leading dev tools.
// redux: DevTools Enhancement
import { createStore } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
const store = createStore(reducer, composeWithDevTools());
mobx has strong reactive inspection tools.
// mobx: DevTools Integration
import { configure } from 'mobx';
configure({ enforceActions: 'observed' }); // Helps catch missing actions
flux is considered legacy technology.
flux package.// flux: Deprecated Pattern
// Avoid using the original flux package for new apps
// Use modern alternatives instead
redux is actively maintained and evolving.
// redux: Modern Toolkit Usage
import { configureStore } from '@reduxjs/toolkit';
const store = configureStore({ reducer: rootReducer });
mobx is actively maintained and stable.
// mobx: Modern Version 6+
import { makeAutoObservable } from 'mobx';
// Fully compatible with React 18 and concurrent features
| Feature | flux | redux | mobx |
|---|---|---|---|
| Data Flow | ποΈ Unidirectional (Dispatcher) | ποΈ Unidirectional (Single Store) | π Observable (Reactive) |
| State Mutation | β Immutable (Manual) | β Immutable (Enforced) | β Mutable (Inside Actions) |
| Boilerplate | π₯ High | π₯ High (Low with Toolkit) | β¨ Low |
| Dev Tools | β οΈ Basic | π Excellent | β Very Good |
| Status | π Legacy | β Standard | β Active |
flux is the historical foundation ποΈ. It introduced the idea of one-way data flow, which fixed many bugs in early web apps. However, it is too verbose for modern development. Use it only for learning history or maintaining very old codebases.
redux is the enterprise standard π’. It trades boilerplate for predictability. If you need to debug complex state issues or work in a large team where consistency matters, Redux is the safe bet. With Redux Toolkit, the pain points are mostly gone.
mobx is the developer experience choice π. It feels like magic because it handles subscriptions for you. If you want to build features fast and prefer object-oriented code, MobX lets you focus on logic rather than wiring. Just be careful with hidden dependencies.
Final Thought: All three libraries aim to make state manageable. flux started the conversation, redux industrialized it, and mobx offered a reactive alternative. For new projects today, choose between redux (for structure) or mobx (for speed), and leave flux in the past.
Choose redux if you need a predictable state container with a large ecosystem, strong dev tools, and a clear separation of concerns. It is ideal for large teams where explicit data flow is critical for debugging and testing.
Choose mobx if you prefer writing less boilerplate code and want state updates to happen automatically without manual wiring. It works well for teams comfortable with object-oriented patterns and mutable state who value developer speed over strict traceability.
Choose flux only if you are maintaining a legacy application built on the original Facebook architecture or need to study the reference implementation of unidirectional data flow. It is not recommended for new projects due to the rise of more modern alternatives.
Redux is a predictable state container for JavaScript apps.
It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. On top of that, it provides a great developer experience, such as live code editing combined with a time traveling debugger.
You can use Redux together with React, or with any other view library. The Redux core is tiny (2kB, including dependencies), and has a rich ecosystem of addons.
Redux Toolkit is our official recommended approach for writing Redux logic. It wraps around the Redux core, and contains packages and functions that we think are essential for building a Redux app. Redux Toolkit builds in our suggested best practices, simplifies most Redux tasks, prevents common mistakes, and makes it easier to write Redux applications.
The recommended way to start new apps with React and Redux Toolkit is by using our official Redux Toolkit + TS template for Vite, or by creating a new Next.js project using Next's with-redux template.
Both of these already have Redux Toolkit and React-Redux configured appropriately for that build tool, and come with a small example app that demonstrates how to use several of Redux Toolkit's features.
# Vite with our Redux+TS template
# (using the `degit` tool to clone and extract the template)
npx degit reduxjs/redux-templates/packages/vite-template-redux my-app
# Next.js using the `with-redux` template
npx create-next-app --example with-redux my-app
We do not currently have official React Native templates, but recommend these templates for standard React Native and for Expo:
npm install @reduxjs/toolkit react-redux
For the Redux core library by itself:
npm install redux
For more details, see the Installation docs page.
The Redux core docs are located at https://redux.js.org, and include the full Redux tutorials, as well usage guides on general Redux patterns:
The Redux Toolkit docs are available at https://redux-toolkit.js.org, including API references and usage guides for all of the APIs included in Redux Toolkit.
The Redux Essentials tutorial is a "top-down" tutorial that teaches "how to use Redux the right way", using our latest recommended APIs and best practices. We recommend starting there.
The Redux Fundamentals tutorial is a "bottom-up" tutorial that teaches "how Redux works" from first principles and without any abstractions, and why standard Redux usage patterns exist.
The #redux channel of the Reactiflux Discord community is our official resource for all questions related to learning and using Redux. Reactiflux is a great place to hang out, ask questions, and learn - please come and join us there!
Redux is a valuable tool for organizing your state, but you should also consider whether it's appropriate for your situation. Please don't use Redux just because someone said you should - instead, please take some time to understand the potential benefits and tradeoffs of using it.
Here are some suggestions on when it makes sense to use Redux:
Yes, these guidelines are subjective and vague, but this is for a good reason. The point at which you should integrate Redux into your application is different for every user and different for every application.
For more thoughts on how Redux is meant to be used, please see:
The whole global state of your app is stored in an object tree inside a single store. The only way to change the state tree is to create an action, an object describing what happened, and dispatch it to the store. To specify how state gets updated in response to an action, you write pure reducer functions that calculate a new state based on the old state and the action.
Redux Toolkit simplifies the process of writing Redux logic and setting up the store. With Redux Toolkit, the basic app logic looks like:
import { createSlice, configureStore } from '@reduxjs/toolkit'
const counterSlice = createSlice({
name: 'counter',
initialState: {
value: 0
},
reducers: {
incremented: state => {
// Redux Toolkit allows us to write "mutating" logic in reducers. It
// doesn't actually mutate the state because it uses the Immer library,
// which detects changes to a "draft state" and produces a brand new
// immutable state based off those changes
state.value += 1
},
decremented: state => {
state.value -= 1
}
}
})
export const { incremented, decremented } = counterSlice.actions
const store = configureStore({
reducer: counterSlice.reducer
})
// Can still subscribe to the store
store.subscribe(() => console.log(store.getState()))
// Still pass action objects to `dispatch`, but they're created for us
store.dispatch(incremented())
// {value: 1}
store.dispatch(incremented())
// {value: 2}
store.dispatch(decremented())
// {value: 1}
Redux Toolkit allows us to write shorter logic that's easier to read, while still following the original core Redux behavior and data flow.
You can find the official logo on GitHub.
This project adheres to Semantic Versioning. Every release, along with the migration instructions, is documented on the GitHub Releases page.