Redux VS MobX | Comparison

Rajitha
Embla Tech
Published in
4 min readJul 15, 2021

In application development using a component-based library like ReactJS, every component is managing its own local state, and the root component usually manages the state for the whole application.

But the problem is as the complexity of the application increases, the component state becomes unstable and it leads to a long process of debugging applications.

The solution is a common state management system such as Redux and MobX. These external libraries are used to transfer state from components as stand-alone testable units and methods for synchronizing application state with individual components. When we use a state management system
data is coming from a central source and that makes the application logic clearer.

Assuming that you are already aware of state management concepts,

What is Redux?

Redux is an open-source JavaScript library used for state management,
popularly known to be used with React.
It is a blend of Flux architecture and functional programming concepts.

What is MobX?

MobX is also a powerful library that makes state management easy and versatile by transparent functional reactive programming (TFRP).
It is basically a state management solution that enables control of the local state inside your application.

Redux vs MobX similarities.

When it comes to a comparison we always should talk about both similarities as well as differences. The major similarity is both of these libraries are used to manage the state in JavaScript applications. They’re usually using with a library like React yet we can use it with any component-based UI library like Angular and Vue. The reason to use it with React is they perfectly
match with react concepts.

Redux VS Mobx comprehensive comparison,

  • Learning

Redux is a mix of flux architecture and functional programming principles. If you are a functional
programmer then you may find learning Redux is super easy for you. But if you are more familiar
with Object-oriented programming concepts then you might confuse at the very first time.
If you work with redux then you have to also learn about how Redux middlewares like Thunk and saga work.

MobX is considered to be somewhat simpler to understand that Redux. Any developer who is
proficient in object-oriented programming concepts finds it easy to learn Mobx.

Also, there are a lot of things going on in the background in Mobx, you don’t have to think about
normalizing the state or implementing principles like Saga or Thunk. It also required less writing code than Redux.

  • Debugging

Redux is offering great developer tools, including time travel. And it has pure functions
and less abstraction, which makes easier the process of debugging.

In MobX, it has more abstraction which makes the process of debugging quite difficult.

  • Data Structure

Redux uses basic Javascript objects as a data structure to store the state. this can become
an overhead when the application has a complex state or when the application is large.

MobX uses observable data to track changes without any worries and automatically vie subscriptions.
This is the main reason that many developers choose MobX over Redux because of this automation.

  • Storage of data.

In Redux, you get access to just one central store which behaves as the source of truth. The state of the store is immutable, which makes things simpler for developers to figure out data. Even though there is a huge JSON object that describes the store, you can still split the code
into a number of reducers. Since Redux is using a single central store it leads to a risk of duplications and uncertainty.

MobX is allowing to use multiple stores which are logically separated. So the state of the
application is not in all one store.

Many applications using at least two major stores, one is for UI state which is unique to the application and the other one is for the domain state. The benefit of maintaining a domain state is
you can reuse this domain state in other applications as well.

  • Purity

In Redux state in the store is immutable, which means that all states are read-only. Actions in Redux can change the state, and reducers can substitute the previous state with a new state. This is what makes Redux pure and predictable.

In MobX, the state is mutable, which means you can easily update the state with new values
making MobX impure and unpredictable.

This is the comparison of Redux and MobX according to my opinion and the next common question is which one should you use?
well, that depends on the application complexity, time, and many more factors.

Thanks for Reading!!! Happy coding :)

--

--