Understanding when to use Jotai and Recoil
Jotai's API is highly inspired by Recoil. In the beginning, it's intentionally designed to help migration from Recoil to Jotai. In this section, we will see a comparison by converting an example with Recoil into Jotai. Then, we will discuss the differences between the two.
Example with Recoil and Jotai
Let's look at the Recoil tutorial at https://recoiljs.org/docs/introduction/getting-started and see how an example in the Recoil tutorial is converted to Jotai.
To start with the Recoil example, we need to import some functions from the Recoil library:
import { RecoilRoot, atom, selector, useRecoilState, useRecoilValue, } from "recoil";
There are five of them used in this example.
The first state for the text string is created with the atom
function:
const textState = atom({ key: "textState", default: "...