Back

Should you use Redux in 2021?

I've been having a ton of fun building two relatively complex React projects this fall.

Until extremely recently I've just been using component state and prop drilling to pass things around. While that's largely been fine for both, it started to become a little painful for one of them about a week ago.

Chatting about this pain to my friend Ryan, he told me to just bite the bullet and start using Redux.

He said:

You’re gonna feel dumb for not setting it up sooner 😉

And well, just days later, here I am. Feeling dumb.

I haven't touched Redux in years, but still remember the pain of setting it up back then. It wasn't pleasant. So I've largely worked to avoid needing it ever since.

Despite the scars, I wanted to give it a fresh try. In just 2-3 hours, I converted all of my state to a single Redux store and reduced (pun intended) my state complexity immensely. I also reduced things by many, many lines of code (many). While the concepts are fairly new and the initial boiler plate is a bit iffy, it was definitely worth getting over the hurdle.

I'm shocked at how approachable it is, and how much better it makes managing state in my app.

Should you use Redux?

Honestly, we've just met! And I don't know a single thing about your project, so I'm not certain!

But!

What I can definitely say is that there are some signs that point to Redux. I'm here to tell you that you shouldn't ignore them.

The internet is filled with articles about when you should or shouldn't use Redux or Context or useReducer or just component state, so I won't even get into it.

So while I'm not saying you should use Redux, I am saying if you've got a moderately complex app, you should definitely try Redux and see how it feels. I'm thrilled that I did.

Where to start

I am neither a doctor nor a Redux expert, but the concensus seems to be to skip Redux and jump straight to Redux Toolkit in 2021.

Start with the Quick Start guide.

Implement that counter as-is in your app and then duplicate it. Try adding another element, like a toggle.

If you're struggling with the initial part of setting up the store, try and just push through that. After it's set up you hardly touch that at all.

When you're all setup, try and move a single piece of your current component state into the Redux store. Then move another piece. Then another.

— 

I was extremely reluctant to even look into Redux for these projects, but I absolutely regret that now. If you haven't looked at Redux in a while, give Redux Toolkit a spin.

I bet you'll find it surprisingly nice, just like I did :^)

Follow along →@saltcod