useRecoilState(state)
Returns a tuple where the first element is the value of state and the second element is a setter function that will update the value of the given state when called.
This hook will implicitly subscribe the component to the given state.
state
: anatom
or a writeableselector
. Writeable selectors are selectors that have both aget
andset
in their definition while read-only selectors only have aget
.
This API is similar to the React useState()
hook except it takes a Recoil state instead of a default value as an argument. It returns a tuple of the current value of the state and a setter function. The setter function may either take a new value as an argument or an updater function which receives the previous value as a parameter.
This is the recommended hook to use when a component intends to read and write state.
Using this hook in a React component will subscribe the component to re-render when the state is updated. This hook may throw if the state has an error or is pending asynchronous resolution. Please see this guide.