Utils
This is an overview over atom creators/hooks utilities that can found under jotai/utils. Each utility is listed below with a link to their description/API.
Overview
The
atomWithStoragefunction creates an atom with a value persisted inlocalStorageorsessionStoragefor React orAsyncStoragefor React Native.The
atomWithObservablefunction creates an atom from a rxjs (or similar)subjectorobservable. Its value will be last value emitted from the stream.Use
useUpdateAtomand write-only atoms to avoid re-render.Returns the value of the given atom.
Creates an atom that could be reset to its
initialValuewithuseResetAtomhook.Resets a Resettable atom to its initial value.
Special value that is accepted by Resettable atoms created with
atomWithReset,atomWithDefaultor writable atom created with atom if it acceptsRESETsymbol.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 to interact with atoms imperatively.
The
freezeAtomtakes an existing atom and returns a new derived atom. The value with the new derived atom will be frozen (= not mutable).Instead of create a frozen atom from an existing atom,
freezeAtomCreatortakes an atom creator function and returns a new function.The
splitAtomutility is useful for when you want to get an atom for each element in a list.The
waitForAllutility is a concurrency helper, which allows us to evaluate multiple async atoms.The primary use case for
useHydrateAtomsare 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.