Redux vs. Recoil

Amir Mohammad Fakhimi
3 min readOct 4, 2023

--

Hi everyone!

In this article, I want to compare Redux vs. Recoil. Hope it’ll be useful and help you in deciding between these two React state managers. Finally, Hope you enjoy it! 😉

It’s one of the three parts of my React state managers collection:

Redux vs. Recoil (Image from here)

Table of Contents

Redux vs. Recoil

  • Flexibility of Coding
    Redux
    provides a centralized storage for managing the state, which means that all of the application’s state is stored in a single location.
    Recoil is more flexible and you can define atoms and selectors everywhere you want.
  • Coding Architecture
    Redux
    encourages separation of concerns, which means that the code related to state management can be kept separate from other parts of the application.
    Recoil doesn’t have any default architecture, but you can follow best practices!
  • Testing
    Redux
    separates state management from the rest of the application, so it is easy to test the state management code in isolation.
    Recoil Doesn’t have this option by default.
  • Complexity of Learning and Using
    Redux can be complex to learn and use, particularly for small applications that don’t require a lot of state management.
    Recoil is simpler than Redux to learn and use, and this feature makes it great for small projects.
  • Boilerplate Code
    Redux
    requires a lot of boilerplate code Because of centralized storage and separation of concerns, which means that it can be time-consuming to set up and maintain. It also influences on Complexity of Learning and Using. This item is really really annoying!
    Recoil needs so less code for a same project. It is so useful specially in small or medium sized projects which needs simplicity and performance together.
  • Performance
    Redux doesn’t have the performance of Recoil. One reason is that Redux isn't dedicated to React projects and it can be used in any JavaScript projects.
    Recoil is dedicated to React, so it is designed to be performant and efficient. It uses a unique approach to managing state that minimizes re-renders and improves application performance.

You can see the summary of the compared metrics in the following table:

Redux vs. Recoil

Experiences

  • Developer Experience
    Redux
    is good at enforcing developer best practices, providing you with a simple pattern to follow so you don’t have to make too many implementation decisions as you build out features. It also allows you to abstract your API requests into actions so everything is held in one single place.
    Recoil has been said to be quite easy to use. It allows you, for instance, to make asynchronous requests in selectors to get started with the state from an API request.
  • User Experience
    Redux
    might need custom implementation, if you wish to manage loading and error states. It is good practice to keep track of a global isLoading variable in the reducer.
    Recoil integrates with React’s latest mode, so it enables you to handle loading states (it’s currently experimental) with Suspense and errors with an ErrorBoundary, allowing you to build your application in a more declarative way.

Conclusion

Redux has been established as the leader in global state management for a while, and it’s certainly not going anywhere soon. However, Recoil is becoming a serious contender for blending in with React.

Redux is a great choice for larger and more complex projects, but Recoil is a good choice for smaller and simpler projects or for developers who are new to state management libraries.

You can compare these two state managers in a real sample project:
Project with Redux
Project with Recoil

In conclusion, both Redux and Recoil are great options for managing state in React applications. The choice between the two will depend on the needs of your project, but both libraries offer a solid foundation for managing state in a predictable and efficient manner.

References

  1. https://www.oneclickitsolution.com/blog/redux-vs-recoil
  2. https://www.imaginarycloud.com/blog/recoil-vs-redux

--

--

Amir Mohammad Fakhimi
Amir Mohammad Fakhimi

Written by Amir Mohammad Fakhimi

I'm Computer Engineering student, now. I'm also interested in Software Engineering and AI. My website is amfakhimi.com

No responses yet