title | description | nav |
---|---|---|
Utils |
This doc describes `jotai/utils` bundle. |
2.02 |
This is an overview of the atom creators/hooks utilities that can be found under jotai/utils
. Each utility is listed below with a link to their description/API.
-
The
atomWithStorage
function creates an atom with a value persisted inlocalStorage
orsessionStorage
for React orAsyncStorage
for React Native. -
The
atomWithObservable
function creates an atom from an RxJS (or similar)subject
orobservable
. Its value will be last value emitted from the stream. -
Use
useUpdateAtom
and write-only atoms to avoid re-render. -
Returns the value of the given atom.
-
Creates an atom that could be reset to its
initialValue
withuseResetAtom
hook. -
Resets a Resettable atom to its initial value.
-
Special value that is accepted by Resettable atoms created with
atomWithReset
,atomWithDefault
or writable atom created with atom if it acceptsRESET
symbol. -
Use this hook to update an atom value with a reducer function.
-
This is a function to create an atom with an embeded reducer function to update the value.
-
This is a function to create an overwritable primitive atom. Its default value can be specified with a read function instead of a static initial value.
-
This creates a new atom that is connected with URL hash.
-
This will create a function that takes param and returns an atom.
-
This function creates a derived atom whose value is a function of the original atom's value, determined by
selector
. -
This hook allows one to interact with atoms imperatively.
-
The
freezeAtom
takes an existing atom and returns a new derived atom. The value with the new derived atom will be frozen (i.e. not mutable). -
Instead of creating a frozen atom from an existing atom,
freezeAtomCreator
takes an atom creator function and returns a new function. -
The
splitAtom
utility is useful for when you want to get an atom for each element in a list. -
The
waitForAll
utility is a concurrency helper, which allows us to evaluate multiple async atoms. -
The primary use case for
useHydrateAtoms
are SSR apps like Next.js, where an initial value is e.g. fetched on the server, which can be passed to a component by props.