Skip to content

Instantly share code, notes, and snippets.

@nilshartmann
Last active May 20, 2021 11:45
Show Gist options
  • Save nilshartmann/64dcfff6f9f7b670c16d80f4fd93be5c to your computer and use it in GitHub Desktop.
Save nilshartmann/64dcfff6f9f7b670c16d80f4fd93be5c to your computer and use it in GitHub Desktop.

I recently (october 2020) evaluated MobX for a project as alternative to Redux (Redux Toolkit).

You can find my very subjective impressions below.

Redux DevTools better than MobX (for me they were more helpful when finding bugs)

Redux is more widely used than MobX

Change/Dependency tracking in MobX is powerful but not always obvious how it works (both behind the scene and in my application). If values didn't update where I expected it, finding the bug sometimes was hard

Class-based and mutable state in React feels strange (not bad, but unusual). On the other hand, having an OO background, I'm familiar with classes and like the concept of classes

In Redux I used a normalized data model. That is not always easy to deal with. My app contains a lot of hierchical data and navigating through it was easier with MobX than in Redux with id-based lookups (MobX: document.getParent(), folder.getDocuments(), even bi-directional references are possbile in MobX)

Calling actions in MobX is very easy and feels smoother than dispatching actions in Redux

Observer components in MobX feels strange (not very React-typical) but are easy to implement and efficient

I made some performance tests (without react, only with stores), and MobX was a little faster than Redux. In my tests I created a very high amount of actions (maybe too much to be realistic) and those actions needed to work on hierachical data a lot.

In MobX stores can access other stores. In Redux a state managemt by one Reducer cannot access another reducer. This is both pro and con I think. Might lead to better, might lead to worse code.

Way more documentation, tutorials, StackOverflow for Redux than for MobX (documentation for Redux outstanding I think)

Documentation of MobX has been consolidated in the last time, but Google still finds old and out-dated pages, that is confusing at the beginning.

Both computed/derived values and lazy initialized values for me are way easier in MobX than in redux. Re-select can help, but for my hierarchical data it either didn't work or was too complicated for me

In Redux an action is passed to all reducers, the whole application can react to each action. In MobX an action is bound to one store (class or object). So for real global actions ("user logged in" for example), Redux might be easier.

The semantic of makeAutoObservable is not obvious for me. What becomes an Action, an observable or a computed property? (Note as of today there is a description in the docs, don't know if it is new or if i have not seen it before)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment