MobX: Bringing Reactive State to React
MobX takes a reactive approach to state management in React by making state observable and letting the UI automatically update when that state changes. Instead of relying on reducers or explicit updates, components simply observe the data they use and react whenever it changes.
When people first explore state management in React, the conversation usually revolves around tools like Redux, Zustand, or Context. These tools generally follow a similar pattern: state changes are explicit, and components update when we intentionally trigger those changes.
MobX approaches the problem from a very different direction.
Instead of focusing on reducers, actions, or dispatching events, MobX introduces a reactive model where state is simply observed, and the UI updates automatically when that state changes.
This idea might feel surprisingly familiar to developers coming from frameworks like Vue.
The Core Idea: Observable State
At the center of MobX is the concept of observability.
State becomes observable, meaning MobX tracks when it is read and when it changes.
When a piece of observable state changes, any part of the UI that depends on it will update automatically.
Rather than manually telling React when to re-render, MobX handles that relationship for you.
The UI simply reacts to the data.
A Store That Looks Like a Plain Class
MobX stores often look like simple classes.
import { makeAutoObservable } from "mobx"
class CounterStore {
count = 0
constructor() {
makeAutoObservable(this)
}
increment() {
this.count++
}
}
export const counterStore = new CounterStore()There is no reducer, no action dispatcher, and no boilerplate structure.
State is defined as normal class properties, and methods update that state directly.
makeAutoObservable tells MobX to track those properties and methods automatically.
Connecting MobX to React
To make React components respond to MobX state, components are wrapped with observer.
import { observer } from "mobx-react-lite"
const Counter = observer(() => {
return (
<button onClick={() => counterStore.increment()}>
{counterStore.count}
</button>
)
})The component renders normally, but something subtle happens during the render process.
MobX tracks which observable values are used by the component. If any of those values change later, the component re-renders automatically.
No explicit subscription logic is required.
Computed Values and Derived State
MobX also makes it easy to derive state from other pieces of state.
Computed values behave like reactive formulas.
get isValid() {
return this.password.length >= 6 && this.email.includes("@")
}Whenever the underlying values change, the computed value updates automatically.
This allows complex state relationships to remain declarative and easy to reason about.
A Different Philosophy from Redux
Redux enforces a very explicit architecture:
action → reducer → store → UIEvery state change must go through reducers, which ensures predictability but often introduces significant boilerplate.
MobX follows a more reactive approach:
observable state → automatic UI updatesInstead of funneling all updates through a single pipeline, MobX observes the state directly and reacts when it changes.
This can make code feel simpler and more natural, especially for applications with complex state relationships.
Why Vue Developers Often Like MobX
Developers coming from Vue frequently feel comfortable with MobX because the mental model is similar.
In Vue, reactive data automatically updates the UI when it changes. MobX introduces that same reactive principle into the React ecosystem.
Rather than structuring everything around reducers or dispatch calls, state behaves more like a reactive data model.
Where MobX Fits in Modern React
MobX is particularly useful when applications have:
- complex shared state
- many derived values
- domain-oriented store models
- interconnected pieces of data
Because MobX focuses on reactivity, it can keep large state models surprisingly concise.
However, the same automatic behavior that makes MobX powerful can also make it feel less explicit than other state management approaches.
Some teams prefer Redux-style predictability, while others prefer MobX’s reactive simplicity.
A Different Way to Think About State
MobX represents a shift in perspective.
Instead of carefully orchestrating how state flows through an application, MobX lets state behave more like a living data model that components observe.
The UI becomes a reflection of observable data rather than a system that needs to be manually notified when something changes.
For developers familiar with reactive frameworks, MobX often feels like bringing that same reactive mindset into the React world.