DEV Community

Discussion on: Why React projects still use Redux

Collapse
 
ejeker profile image
Eric Jeker

Thanks Alexandru-Dan for this article. I am not well versed in React (for now) but having created many applications in Angular I can tell you the Redux fatigue is here. Luckily we have good toolkits and best practices but we often end up with a different implementation by developer by team.

The most common question is: Should everything be in Redux? Should every action performed in the application be handled by Redux? Common sense tells me that Redux should only manage (persistent) state, but then come a problem because we end up with a very hybrid solution with some actions (search, filters, authentication) in Redux and some others not (CRUD like actions on an entity).

I still like Redux but it adds a lot of boilerplate and complexities and it is sometimes very hard to teach it in teams of junior or mid-level developers. This is sometimes a point that is overlooked by documentations in the sense that when we manage multiple teams and multiple developers the best solution is often the most universal, opinionated and strict as to avoid too many different implementations that increase technical debt and decrease readability and maintainability.

And it's becoming even more difficult because of SSR and Pre-Rendered Sites as state is not (easily) shared between server and client.

So it's nice to read different opinions on the question of Redux.

Collapse
 
alexandrudanpop profile image
Alexandru-Dan Pop

Good points!

I think Redux is getting more mature with solutions like Redux Toolkit & RTK Query (that is still alpha but sounds promising).

Angular also has the NGRX store that is a Redux-like implementation for the Angular ecosystem - I think this proves the Redux popularity.

React Query is another popular solution to avoid boilerplate - but this one has a learning curve as well for advanced usage. But it's nice because it will invalidate and re-fetch the cached data.

SSR & pre-rendered sites - haven't used Redux in those scenarios - so I honestly can't make a statement for it. I only used Redux for fully CSR apps.

As a small conclusion, if you spend too much time researching what advantages Redux brings or what cons it has, you might not need it. You will know when you need it in those cases:

  • state is hard to manage
  • state has complex updates
  • state is shared in multiple different components or pages of the application
  • state tracking is important
  • you want to test the state updates