DEV Community

Why I stopped using Redux and Used Recoil Instead

Akash Shyam on March 31, 2021

What's wrong with Redux? Redux is not perfect, but it is by far the most popular state management library used with React. Let's look at...
Collapse
 
diogo405 profile image
Diogo Goncalves

I don't know why people still use Redux. Recoil is much simpler and easier!

Collapse
 
johnfrades profile image
John Frades

Redux is already an established library and well maintained. If you're working on a commercial product, adding a library because its simpler and easier isn't always the case. Especially that Recoil is still in Experimental stage. Companies jwouldn't risk their product using an experimental stage library

Collapse
 
nicozerpa profile image
Nico Zerpa (he/him)

Redux has been so popular for a long time. That means there are lots of libraries that work well with it. As Recoil is still a young project, you don't have so many libraries available, at least for now.

Also, there are tons of information online about Redux. That's very useful if you find a bug or a problem using the library because it will be easier to find how others solved that problem.

If you use Recoil and something goes wrong, it will be way harder to google how to solve it. That's also because it's a new tool.

Redux is better suited for large, complex applications. In these large codebases, the boilerplate code isn't that much of a problem.

Collapse
 
stojakovic99 profile image
Nikola Stojaković • Edited

Most probably because of the ecosystem. That's one of the primary reasons why most of the websites still use PHP. Also, Recoil is an experimental library.

Collapse
 
jyooi profile image
jyooi

I don't know why those people thinking of other ppl using that library are not a good idea. They don't understand there always have the legacy codebase and it is still working fine. People don't risk their production code with those experimental libraryy.

Collapse
 
foyzulkarim profile image
Foyzul Karim

Still there are thousands of React apps which are using class components, for various reasons. How can we use recoil in these projects?
What I do is, I mix and match the redux and react state in my app and it works just fine.

Collapse
 
akashshyam profile image
Akash Shyam

If you look at the title, i'm not asking people to switch to recoil and throw redux in the bin. I'm just saying my viewpoint. If a beginner is learning react and has just learned the concept of "hooks".... recoil is much easier to grasp. Then maybe he can move onto redux. I took almost 2-3 months to properly grasp redux. On the flip side, i learned recoil in a day or two. Redux has so many ways to dispatch/connect to state and when we use something like redux thunk we have a different way of dispatching. I'm not saying not to use redux, I'm just advocating recoil as an option. Of course recoil has it's disadvantages.

Collapse
 
blowfish profile image
Blow Fish

I've been using recoil in production and I know others who use it in production too.
I disagree with people saying what if so and so happens . Tbh there isn't a lot that can go wrong (Its not redux) . Also not to forget that recoil has 13k stars on github and for a good reason.

In the end it all matters where you want to fall in the technology lifecycle.
Yes you will be early adopters but the ease to work with recoil makes it very favourable.

I'm not saying to ditch Redux halfway (you probably shouldn't). It does it's job well, but do give recoil a try for your next project 💁🏻‍♂️

Collapse
 
scottishross profile image
Ross Henderson

We seriously considered Recoil, but for a commercial product we were concerned that the support for it just wasn't there yet. In a few years it'll be more popular that Redux, we think, but we just can't take that risk.

Collapse
 
akashshyam profile image
Akash Shyam

Did you guys consider zustand?

Collapse
 
scottishross profile image
Ross Henderson

I haven't heard of it, I'll have a look!

Collapse
 
nicozerpa profile image
Nico Zerpa (he/him)

So, Recoil is inspired by React Hooks... interesting!
Thank you for sharing, Akash 💯

Collapse
 
akashshyam profile image
Akash Shyam

Glad you liked it!

Collapse
 
chasm profile image
Charles F. Munat

So atom and selector are in global state somehow? I don't see where they are imported. And how does RecoilRoot know about them?

This doesn't make much sense to me. What am I missing?

Collapse
 
akashshyam profile image
Akash Shyam

Atom and selector are not in global state.... they have to be imported.

Collapse
 
chasm profile image
Charles F. Munat

So maybe show the imports in your examples? Examples should be complete and not assume any prior knowledge of the code you're explaining.

Thread Thread
 
akashshyam profile image
Akash Shyam

Actually the code snippet was getting very big and I did not want to bore the reader by showing the imports. Will add imports from now on, thanks!

 
akashshyam profile image
Akash Shyam

I agree with you. Only stuff like auth should be stored globally. We should try and keep as much as we can in component level state except when we have to share props downwards in the component tree by many levels.

Collapse
 
drarig29 profile image
Corentin Girard • Edited

You are not importing useRecoilState() in the first snippet you mention it.

Collapse
 
akashshyam profile image
Akash Shyam

Thanks for the tip.... sorry about that input

Collapse
 
oliverradini profile image
OliverRadini

Is it possible to use recoil with frameworks/libraries other than react? One thing I like about Redux is that it disconnects state management from the rest of the frontend stack.

Collapse
 
akashshyam profile image
Akash Shyam

A state management library for React
Recoil official Website

Recoil was designed specifically for react to make it easy to use and adhere to the react idealogy

Collapse
 
oliverradini profile image
OliverRadini

One of the main advantages I've seen with React is that it doesn't try and enforce an ideology across the stack, but allows you to choose your own tools. I think that a distinct advantage of redux is that state management is framework agnostic.

Collapse
 
lyrod profile image
Lyrod

Import from 'root' ?

Collapse
 
akashshyam profile image
Akash Shyam

Thanks for letting me know.... it was a typo

Collapse
 
jivkojelev91 profile image
JivkoJelev91

You can take a look in Redux-toolkit.

Collapse
 
milindsoorya profile image
milindsoorya

I am trying to implement recoil but is stuck on how to properly structure it. Are there any production-ready, battle-tested approaches that you know of?

Collapse
 
blowfish profile image
Blow Fish

What I like to do is create a folder in root called "states" and atoms and selectors of each logic goes in one file. Like user atoms and selectors goes in states/user.js. Absolute imports will make your code more readable and easy to work with

Collapse
 
ajayjayapalan profile image
ajayJayapalan

Can we create a state setter in parent component or something and use it in the child component without passing through props ?