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...
For further actions, you may consider blocking this person and/or reporting abuse
I don't know why people still use Redux. Recoil is much simpler and easier!
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
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.
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.
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.
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
andreact state
in my app and it works just fine.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.
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 💁🏻♂️
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.
Did you guys consider
zustand
?I haven't heard of it, I'll have a look!
So, Recoil is inspired by React Hooks... interesting!
Thank you for sharing, Akash 💯
Glad you liked it!
So
atom
andselector
are in global state somehow? I don't see where they are imported. And how doesRecoilRoot
know about them?This doesn't make much sense to me. What am I missing?
Atom and selector are not in global state.... they have to be imported.
So maybe show the imports in your examples? Examples should be complete and not assume any prior knowledge of the code you're explaining.
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!
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.
You are not importing
useRecoilState()
in the first snippet you mention it.Thanks for the tip.... sorry about that input
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.
Recoil was designed specifically for react to make it easy to use and adhere to the react idealogy
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.
Import from 'root' ?
Thanks for letting me know.... it was a typo
You can take a look in Redux-toolkit.
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?
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
Can we create a state setter in parent component or something and use it in the child component without passing through props ?