Jotai or Recoil: A New Era of State Management in React — A Comparison with Redux & Zustand.

Kumar Parth
4 min readAug 5, 2023

--

Introduction

Gone are the days of complicated state management in React applications! Meet the new contenders, Jotai and Recoil, the dynamic duo set to revolutionize the way you handle state in your projects. In this article, we’ll embark on a delightful journey, pitting Redux, the seasoned veteran, against the fresh and crispy newcomers, Jotai and Recoil. We’ll also sprinkle in a dash of Zustand for extra flavor. Let’s explore how these libraries stack up in terms of bundle size, app size bloating, usage simplicity, documentation, support, and a pinch of code snippets to whet your appetite. 🍿🍩

1. Bundle Size and App Size Bloatedness 📦

In the world of modern web development, smaller is better! Redux, though robust, tends to bulk up your app with its plethora of dependencies and boilerplate code. Say hello to Jotai and Recoil, the lean and mean contenders. With minimalist architectures and fewer dependencies, they bring a refreshing breeze of optimized bundle sizes, ensuring your users’ experience is nothing short of delightful. 🌟

2. Usage Simplicity: Redux vs. Jotai vs. Recoil vs. Zustand 🚀

Redux, the ever-reliable workhorse, has served us well, but it does require adhering to a strict pattern of actions, reducers, and stores. Jotai and Recoil, like sweet symphonies, resonate with simplicity and ease.

  • Jotai: With its atom-based approach, each state becomes an independent atom, promoting composability without cumbersome reducers or complex setup. Sweet simplicity, no boilerplate required! 🌱
  • Recoil: Embracing the harmony of “atoms” and “selectors,” Recoil strikes the perfect balance between declarative and intuitive state management. So satisfying! 🎵
  • Zustand: Ah, the underdog of the pack! Zustand introduces a delightful blend of Redux-like state management with the simplicity of hooks. Tasty and versatile! 🍨

3. Documentation and Community Support 📚

Redux boasts an extensive legacy, with a cornucopia of documentation and a vibrant community backing it up. But wait, Jotai and Recoil are catching up at warp speed! 🚀

  • Jotai: Stepping up its documentation game, Jotai’s budding community is thriving. Being part of the React ecosystem adds a sprinkle of familiarity, making it easy to find helpful resources. 🌱🌍
  • Recoil: The heavyweight contender, backed by Facebook itself! With its detailed and ever-evolving documentation, Recoil boasts top-tier support. Facebook’s seal of approval adds a dash of reliability to the mix. 👍
  • Zustand: Don’t underestimate the power of the underdog! Zustand’s fast-growing community brings fresh and inventive solutions to the table. It’s like discovering a hidden gem! 💎

4. Performance Showdown

In the race for optimal performance, all contenders aim for the crown!

  • Redux: With proper optimizations, Redux can shine brightly. Its legacy speaks for itself! 🏆
  • Jotai: Leaning on React’s built-in Context and useContext hooks, Jotai breezes through rendering like a pro. Minimalist and fast! 🏎️
  • Recoil: In anticipation of React’s concurrent mode, Recoil flaunts its performance finesse. Ready to tackle the future with grace! 🌟
  • Zustand: Not to be outdone, Zustand’s lightweight approach and simplicity dance hand in hand, delivering a swift and snappy experience. ⚡

5. Ecosystem and Integrations 🌐

Ah, the ecosystem, where the flavors of integration intertwine!

  • Redux: A behemoth of an ecosystem, adorned with middleware and developer tools galore. A feast for integration enthusiasts! 🌈
  • Jotai and Recoil: The new kids on the block, rapidly gaining momentum with support for popular tools like Redux DevTools, React Query, and more. Adapting to new flavors with ease! 🚀
  • Zustand: The gourmet meal of simplicity, Zustand embraces its hook-based nature, making integrations seamless. Mixing and matching at its best! 🔗

A Dash of Code Snippets 💻

Let’s whet your appetite with a taste of each library’s syntax:

// Redux
const increment = () => ({ type: ‘INCREMENT’ });
const counterReducer = (state = 0, action) => {
switch (action.type) {
case ‘INCREMENT’:
return state + 1;
default:
return state;
}
};
// Jotai
import { atom, useAtom } from ‘jotai’;
const countAtom = atom(0);
const MyComponent = () => {
const [count, setCount] = useAtom(countAtom);
// …
};
// Recoil
import { atom, useRecoilState } from ‘recoil’;
const countAtom = atom({ key: ‘count’, default: 0 });
const MyComponent = () => {
const [count, setCount] = useRecoilState(countAtom);
// …
};
// Zustand
import create from ‘zustand’;
const useStore = create((set) => ({
count: 0,
increment: () => set((state) => ({ count: state.count + 1 })),
}));
const MyComponent = () => {
const count = useStore((state) => state.count);
const increment = useStore((state) => state.increment);
// …
};

Conclusion 🏁

Now that you’ve savored the delightful flavors of Redux, Jotai, Recoil, and Zustand, the choice is yours. Each library brings its own unique zest to state management in React. Consider your project’s needs, your team’s taste, and the complexity of your application. Whether you favor Redux’s seasoned legacy, Jotai and Recoil’s fresh simplicity, or Zustand’s delicious blend of both, rest assured that these state management libraries will spice up your React development like never before. Happy coding and bon appétit! 🍿🎉

--

--