Recoil.js is a state management library, open-sourced by Facebook. It's offering a simple and powerful way of dealing with global, asynchronous and derived state.
We'll show basic usage of Recoil API with simple counter example.
Refer to official documentation for detailed usage. →
We need to wrap our code with RecoilRoot in root component.
atom is simply a unit of state that component can subscribe. By updating the value, each subscribed component is re-rendered with the new value.
To read and write an atom from a component, we use a hook called
Clicking on the buttons will update state and change count. It's that simple.
We recommend watching Dave McCabe's presentation about Recoil to understand the logic behind the Recoil.
All required configurations will be handled automatically by CLI as long as you choose Recoil plugin during the project creation phase.
If you didn't choose Recoil plugin during project creation phase, you can follow the instructions below to add it.
Refer to official documentation for installation.