React State Management Made Easy: An Intro to Recoil

Tharaka Romesh
The Startup
Published in
4 min readMay 19, 2020

--

Recoil is a state management library for React, maintained by Facebook's experimental and open-source group. Several state management libraries like Redux, Flux, Mobx, which were introduced to manage the state in their different methods, lacked some aspects where others shine. Redux was the most famous and widely used in the React community due to the single source of truth (single store) and the concept of immutability but had more boilerplate. Flux can be considered a predecessor for Redux, where it had several stores and dispatchers. It didn't follow any immutability concepts, leading to various memory leaks in the applications. MobX uses observable data, which helps in automatically tracking changes through implicit subscriptions, but it was not immutable.

Later Facebook introduced a method to handle state through React’s Context API, but I also did not address the issues of Redux. So now Recoil comes into the game. Recoil provides several capabilities that are difficult to achieve with React alone while being compatible with the newest features of React. React has certain limitations.

  • The component state can only be shared by pushing it up to the common ancestor, but this might include a huge tree that needs to re-render.
  • Context can only store a single value, not an indefinite set of values, each with its consumers.
  • Both of these make it challenging to code-split the top of the state trees which hold the data.

--

--

Tharaka Romesh
The Startup

I’m a Full Stack Developer at Anyfin AB who is passionate about new technologies and writing tech blogs. Reach me at tharakaromesh@gmail.com