You probably don't need Redux anymore

March 7, 2019

This is a follow-up post to Why should I consider React + Redux, where I outlined the benefits of using Redux in your React applications. Even after Dan Abrimov’s popular post You Might Not Need Redux, I felt that Redux added enormous value in applications at scale. However, that was back in August 2017, and a lot has changed since then.

My intention here will be to briefly describe why you really don’t need Redux, and dive into how thinking differently about your architecture can have huge benefits. In its prime, Redux solved the very real problem of scaling out state management in large, and complex, React applications. However, if you have the luxury of being in control of the integration layer, I highly recommend that you set up a GraphQL server to sit between your React application and the REST API. Then, install react-apollo and start hacking.

Let me take a step back and say that if you’re not using GraphQL, you should definitely give it a try. I’ve always been a big fan of micro-services. However, the complex deployments, fractured APIs, and general cost of maintenance was sometimes a deterrent. GraphQL helps you neatly organize your services behind one schema-based API. This is very beneficial for front-end applications since it can focus on integrating with just one API, and leave the vast majority of that complexity to the GraphQL implementation.

Once you are convinced that GraphQL is the way to go, you will quickly realize how much more powerful GraphQL + React Apollo is over a typical REST API + Redux implementation. You’ll find that the GraphQL implementation has much less boilerplate code and is more concise. State management feels natural since you’re not doing anything extra. React Apollo handles caching the data for you. And if you need to update the cached data because of a mutation, that’s easily taken care of as well. I’ll get into more of these details in a later post.

If you have no control over the integration layer, then take a look at React Hooks. Actually, you should be using React Hooks regardless :). Hooks don’t directly replace Redux, but they do make it far less appealing. Together with React’s Context, you can easily find yourself building scalable front-end applications without Redux.

In conclusion, the React ecosystem has matured beyond Redux. Consider leveraging the power of GraphQL together with React Apollo.