What Is Recoil and an Atomic State?

Learn how to categorize state management libraries into Flux, Proxy, and Atomic types, and explore the Jotai library.

We'll cover the following

New state management libraries pop up every few weeks; they are sometimes purely open-source and sometimes company-backed. However, they rarely propose groundbreaking solutions. More often than not, they are newer implementations of known concepts. Those implementations are greatly appreciated because every developer likes working comfortably—and what are those known concepts, you might ask?

Types of libraries

There’s a consensus in the ReactJS world that state management libraries can be divided into three types:

  • Flux type: These are state management libraries that hold the state outside of components and use a unidirectional data flow. They are inspired by Facebook’s Flux, the most famous example being Redux. There are modern implementations of this flow, such as Redux Toolkit or Zustand.

  • Proxy type: These libraries wrap the state, conceptually similar to what a proxy does. When using this type of state management, the developer can subscribe to and read wrapped values like any other values in the component. The best examples of proxy-type state management are React’s Context, MobX, or Valtio.

  • Atomic type: This is the state set at the lowest level, managed naturally by setState in-class components and the useState hook in function components. Values set in this way can be passed around the app and used in a bigger context. Facebook created an experimental library to promote this type of state management, called Recoil. Jotai soon followed suit.

Recoil

Recoil was created around mid-2020 and quickly garnered lots of attention. It was published by Facebook itself, the creators of React, so everyone was expecting a great new solution. The idea of using the smallest possible denomination of pieces of state, peppered and accessible throughout React apps, was enticing. Unfortunately, after the first gasp of excitement, a big part of the React community lost interest in Recoil and went about their days continuing to work mostly with Redux. Two years later, Recoil’s documentation still states that it’s experimental, and few people are talking about it.

Get hands-on with 1200+ tech skills courses.