Skip to content

Fix React MobX Observable – UI Not Reacting to Changes

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Fix React MobX Observable. We cover key concepts, practical examples, and best practices.

You define a MobX store with makeAutoObservable, use it in a React component via <a href="/design-patterns/observer/">observer</a>, update a property — and the UI stays frozen. The store value changes (confirmed in DevTools), but the component doesn't re‑render.

Wrong ❌

// store.js
import { makeAutoObservable } from 'mobx';

class CounterStore {
  count = 0;

  constructor() {
    makeAutoObservable(this);
  }

  increment() {
    this.count += 1;   // updates the property
  }
}

export const counterStore = new CounterStore();

```jsx
// Counter.jsx — NOT wrapped with <a href="/design-patterns/observer/">observer</a>
function Counter() {
  return (
    <div>
      <p>Count: {counterStore.count}</p>
      <button onClick={() => counterStore.increment()}>+1</button>
    </div>
  );
}

Clicking the button updates `counterStore.count`, but the component shows the old value.

## Right ✅

```javascript
// store.js
import { makeAutoObservable } from 'mobx';

class CounterStore {
  count = 0;

  constructor() {
    makeAutoObservable(this);
  }

  increment() {
    this.count += 1;
  }

  get double() {
    return this.count * 2;   // computed value
  }
}

export const counterStore = new CounterStore();

```jsx
// Counter.jsx — wrapped with <a href="/design-patterns/observer/">observer</a>
import { <a href="/design-patterns/observer/">observer</a> } from 'mobx-react-lite';
import { counterStore } from './store';

const Counter = <a href="/design-patterns/observer/">observer</a>(() => {
  return (
    <div>
      <p>Count: {counterStore.count}</p>       {/* re-renders ✅ */}
      <p>Double: {counterStore.double}</p>      {/* computed ✅ */}
      <button onClick={() => counterStore.increment()}>+1</button>
    </div>
  );
});

export default Counter;

Now every click increments the display:

Count: 5
Double: 10

**If using class components:**

```jsx
import { observer } from 'mobx-react';
// Use `observer` as a HOC
@observer
class Counter extends React.Component {
  render() {
    return <p>{counterStore.count}</p>;
  }
}

**Debugging — check observable tracking:**

```<a href="/programming-languages/javascript/">javascript</a>
// Open the component in React <a href="/web-development/tools/chrome-devtools/">DevTools</a>
// It should show "<a href="/design-patterns/observer/">Observer</a>" in the component tree
// If it shows "Counter" without "<a href="/design-patterns/observer/">Observer</a>", the HOC is missing

## Root Cause

MobX's reactivity relies on `<a href="/design-patterns/observer/">observer</a>()` wrapping React components. Without it, React treats the component as a regular function component and doesn't subscribe to MobX observables. The observable updates, but React has no way to know it should re‑render.

## Prevention

- Always wrap components that read observable values with `<a href="/design-patterns/observer/">observer</a>()`.
- Use `mobx-react-lite` for function components, `mobx-react` for class components.
- Use `computed` getters for derived values to avoid recomputation.
- Keep `makeAutoObservable` in the constructor to automatically wrap all properties.


## Common Mistakes with mobx observable

1. **Using `foldl` instead of `foldl'` causing stack overflow on large lists**
2. **Forgetting `deriving (Show, Eq)` on custom data types needed for debugging**
3. **Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable**

These mistakes appear frequently in real-world REACT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

## Practice Exercise

**Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.**

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

## FAQ

<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Can I use MobX without `<a href="/design-patterns/observer/">observer</a>`?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Yes — but you must manually call <code>forceUpdate()</code> or use <code>useLocalObservable</code> for local state.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Why does my array push not trigger a re‑render?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: <code>makeAutoObservable</code> wraps arrays with observable array. Use <code>.push()</code> or <code>.replace()</code> — direct index assignment like <code>arr[0] = x</code> isn't tracked.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: How do I share a store across components?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Use React Context: <code>const StoreContext = createContext(counterStore)</code> and <code>useContext(StoreContext)</code>.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Does MobX work with React 18 concurrent features?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Yes — <code>mobx-react-lite</code> v3+ supports React 18 and <code>useSyncExternalStore</code>.</p>
</div></details>

---

*MobX integration is covered in the [DodaTech React State Management course](https://dodatech.com/courses/react-state).*

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro