Search code examples
reactjsreduxmobx

Is mobx-react-lite is a good choice for state management in large react application?


mobx is easier to learn and apply than redux, but not sure, whether it introduces any blocking or drawbacks for large enterprise applications.

If anyone using mobx-react-lite for enterprise applications, please share your experience. Is Redux still the best state management ? even after the context API and hooks :(

Update:2022/2023 Try to solve your state requirements with Recoil , surely, this will be a part of React library in future


Solution

  • Short response: sure, it works for big apps.

    That said, you can not really compare Mobx to Redux.

    Mobx is a library that lets you implement functionalities with the observer pattern. Redux is a library specialised for state management. So, with Mobx, doing state management is just one of the possibilities it offers. For example, I use it to share some models between frontend and backend (Nodejs), so it's less work. But, since it's lower level, there are some things you need to figure out by yourself, such as how to structure your state, the relations between your models and dependency injection. On the other hand, the advantage of Redux is that being more opinionated, with a huge community you can find solutions more easily.

    To each his own experience, personally I use bare Mobx in big and small apps and won't go back to Redux, that complicates everything. In practice I've seen a few codebases where developers were "cheating" and implementing anti-patterns in order to skip some of the boilerplate that comes with Redux, destroying all the benefit of predictability.

    You could have a look at mobx-state-tree that is a more opinionated solution for app state based on Mobx, like Redux. (I haven't used it, as I prefer the flexibility of bare Mobx).

    In summary, there is no reason Mobx works worst for big apps. Redux, like any tool, including Mobx, does not have anything special that can prevent a codebase from turning into a big mess.

    Edit: There is also this newer project using mobx for state management. I haven't tried it. mobx-keystone