loading...
Cover image for Should You Learn Redux?

Should You Learn Redux?

mercatante profile image Steven Mercatante Updated on ・3 min read

This post was originally published at stevemerc.com


(In case you're unaware, Dan co-created Redux.)

Ever since React's context API became stable, and especially after the release of hooks, a boatload of posts told us that Redux was on its deathbed. Who needs Redux when we've got the context API? Who wants to write all that boilerplate code? It's way too verbose when all I want to do is push an item to an array!

I don't necessarily disagree with those sentiments. Redux can be a pain to use, but sometimes it's the right choice for a project.

I want to pause here and say that I'm really grateful for Redux. Its creators and maintainers have spent a ton of time and energy in making a powerful tool. I've made good money working on projects that use it. And it's probably single handedly responsible for teaching more people how reduce works than anything else.

So, Should You Learn Redux?

When a post asks if you should learn something, the answer is usually "it depends." But not this post. Yes, you should learn Redux.

Regardless of the flak it gets, it's still the most popular state management library for React apps. It's battle tested, has incredible tooling, and there's a large community around it. If you've got a question, someone's already answered it.

This means that you're likely going to encounter and work on a project that uses it. And no matter how much you protest that there's a better option (maybe there is, maybe there isn't), you're gonna have to use it. So, rather than fight it, embrace it.

The official docs are great. Spend some time with them. Redux isn't the easiest library to grok, which is why knowing how it works is useful before you find yourself neck deep working in a project that uses it.

I'd also recommend learning how Reselect and Immer work. They're not necessary to use Redux, but they can improve performance and readability, and it's not uncommon to see them used alongside Redux.

[Edit: also check out Redux Starter Kit, mentioned by Mark Erikson in the comments below.]

Should You Use Redux?

This is where I respond with "it depends". Personally, I've stopped using Redux for new projects. Local state and the context API can get you very far. And when I need something more powerful, I use MobX. The balance it strikes between Redux and not-Redux is great. But, as a consultant, I often find myself working on projects that use Redux, and knowing how it works is essential.

In the end, the choice to learn Redux and the choice to use it are two different things. I think it's at least worth learning.

👋 Enjoyed this post?

Join my newsletter and follow me on Twitter @mercatante for more content like this.

Posted on by:

mercatante profile

Steven Mercatante

@mercatante

Hey, I'm Steven Mercatante and I build things for the web. I'm a full stack software engineer with over 15 years of experience building websites, mobile apps, APIs, CMSs, and ETL pipelines.

Discussion

markdown guide
 

One thing I'd also add about redux is the amazing tooling via the Redux DevTools.

GitHub logo zalmoxisus / redux-devtools-extension

Redux DevTools extension.

Redux DevTools Extension

Join the chat at https://gitter.im/zalmoxisus/redux-devtools-extension PRs Welcome OpenCollective OpenCollective

Demo

Installation

1. For Chrome

2. For Firefox

3. For Electron

4. For other browsers and non-browser environment

Usage

Note that starting from v2.7, window.devToolsExtension was renamed to window.__REDUX_DEVTOOLS_EXTENSION__ / window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__.

1. With Redux

1.1 Basic store

 

The Redux devtools is amazing. I have nothing but good things to say about it.

 

I think this is fitting as well

 

Ha! I was wondering if I should add that to this post when I was writing it. I could've used you as an editor!

But yes, Jani makes a great point.

 

Hi, I'm a Redux maintainer. I know you know my opinion already, but I wanted to pop in and offer my thoughts for anyone else reading this post.

First, related to the "Redux is dead" meme: I specifically addressed this in my Reactathon 2019 talk on "The State of Redux" and my post Redux - Not Dead Yet!. The TL;DR version is:

  • Redux is still widely used (50% of React apps), and overall usage is still growing
  • There are definitely lots of other options (context+hooks, GraphQL, MobX, etc) that overlap with how you'd use Redux, and that means you don't need to use it all the time the way you maybe would have before
  • But, there's also lots of good reasons to choose to use Redux
  • Overall, the important thing for any project is to know what your needs and use cases are, evaluate the tradeoffs for each option, and deliberately pick the tool that makes the most sense for that app.

Specifically to the common question of "do hooks/context kill Redux?", see these additional articles:

I do think that almost everyone should learn Redux. Not only will you probably run across projects that use it, but understanding how it works and how to use it will definitely have a major effect on how you approach solving problems.

Per your comments on the docs and Reselect/Immer:

Folks should check out our new official Redux Starter Kit package. It includes utilities to simplify several common Redux use cases, including store setup, defining reducers, immutable update logic, and even creating entire "slices" of state at once without writing any action creators or action types by hand. It's powered by Immer inside, includes Reselect, and is our recommended default approach for writing Redux logic:

redux-starter-kit.js.org

And finally, we're starting a major rewrite of the Redux core docs. It'll be a long-term effort, but I think we can make the docs better and easier to understand.

Hopefully that helps add some clarity. If anyone has questions, ask away!

 

Hi Mark, thanks for chiming in!

Overall, the important thing for any project is to know what your needs and use cases are, evaluate the tradeoffs for each option, and deliberately pick the tool that makes the most sense for that app.

^ A million times, this.

Thanks for mentioning Redux Starter Kit; I should've included that in this post.

 

What is a greenfield project? Also you suggest learning redux but you have stopped using it and now use mobx! It's kinda confusing where you want to direct your readers.

 

Sorry if it's confusing. I'm recommending that folks learn Redux, but not necessarily use it for their own projects (that's completely up for you to decide.) This is coming from the point of view that React developers are likely to work on projects that use Redux (think existing client work), so knowing how to use Redux is valuable knowledge.

 

Thanks, it would have been more clear if you had included this in blog as well. i am just learning react and find redux very complex so i don't wanna jump into it but every project i work on use redux so i have to learn it even though there are other options like you mentioned.

 

A greenfield project means a brand new project, as in not based on existing code.

Brand New

 

Like you said, eventually, you might need to work on react+redux apps, so it's still a must to learn in my opinion for react devs out there. Context & hooks are still not as popular as redux/mobx in bigger companies who are already using react+redux/mobx. They won't change their existing large codebase because it's the new hottest thing. Maybe they will give it a shot on a greenfield, less impactful project.

Anyway, nice article! :)

 

I would recommend every developer to take a close look at redux and make an effort to really understand it. The library (i.e. the actual implementation) in and on itself is actually secondary in this case, but the concept (single-directional data flow + persistent data structures) is very powerful and a useful tool to have on your belt in many other cases, even outside UI and Javascript. I feel that I learned a lot about proper data flow by studying it, and I'm not even a real frontend developer.

 

Nice post! thanks for sharing it, i'm actually using react, redux and node.js in my actual job and i really enjoy a lot using redux and redux devtools.

 

Glad to hear you’re enjoying it. Have you tried Reselect or Immer with Redux?

 

Yes! i used reselect to optimize my React/Redux apps!

 

Why not? I there any better alternative? In my opinion the "hooks & context" solution doesn't help, it generates code mess.

 

"Better" is subjective per project. Sometimes Redux is the right choice, sometimes it's not. Hooks & context aren't messy in and of themselves; they're tools (just like Redux, MobX, etc.)