4 ms·
While Redux is much better than early Flux implementations, I feel that both have the same issues: quite a lot of boilerplate, scattered logic and confusion aro
by jorde 10y ago
While Redux is much better than early Flux implementations, I feel that both have the same issues: quite a lot of boilerplate, scattered logic and confusion around best practices. Don't get me wrong, I really like Redux but I feel that most of the time I'm writing either boilerplate code or trying to decide how to structure my actions and reducers. Also combining actions/reducers with components isn't particularly easy given that you still need to combine reducers into one state. Not to talk about cherry picking parts of state into props and then working with reselect to cache values or normalize API responses...
Oh sorry, I think I had something that I needed to let out :)
Anyway, recently I discovered MobX[1] which, aside from the bad name, is amazing. It's pretty flexible and has very small API surface but compared to Redux it just gets out of the way. Granted, there's a lot of hidden logic which feels like magic but in the end it allows me to build apps way faster while still producing performant code. I have moved few projects from Redux to Mobx and it's mainly removing code and files and bundling mobx stores with components. At work I been able to explain it to coworkers in two minutes where as it has taken hours or days for people to understand Redux. I highly recommend checking out the React+MobX tutorial[2] and give it a go even though it's not the hot thing of the week just yet :)
[1] https://mobxjs.github.io/mobx/ https://mobxjs.github.io/mobx/
[2] https://mobxjs.github.io/mobx/getting-started.html https://mobxjs.github.io/mobx/getting-started.html
- groovytime 10y agoHeaven for bid you actually have to understand how/why something works and not just have "magic" happen.
- Glide 10y agoMobx needs more love. For flexibility I am leaning towards making MobX as a choice in projects and then being able to build up towards an architecture like Flux in an application.
- lucidrains 10y agoSecond this, mobx is awesome
- tracker1 10y agoDon't map your reducers/actions to the components... map them to the data/features they are tied to. If you organize by feature, you don't really have to have your actions/dispatchers sitting with your components, but you can where it makes sense.
- tracker1 10y agoJust to expand... as an example... .../features/users/login may contain both the ui components as well as specific actions/reducers related to login... though other components may call actions under features/user as necessary, because they correlate to the data/features/functionality around users, where the components themselves may be for other features. I feel that once you stop trying to segregate by either component or type of module/script that it tends to be far easier for someone new to come up to speed in a project. It is taking practice and some thought, but has worked very well where I've implemented this approach so far.