Open History to see the last commit
function useAtom<TValue>(atom, options?): [Accessor<TValue>, (fn) => void & (value) => void];
Defined in: useAtom.ts:23
Returns the current atom accessor together with a setter.
Use this when a component needs to both read and update the same writable atom.
Type Parameters#
TValue#
TValue
Parameters#
atom#
Atom<TValue>
options?#
UseSelectorOptions<TValue>
Returns#
[Accessor<TValue>, (fn) => void & (value) => void]
Example#
const [count, setCount] = useAtom(countAtom)
return (
<button type="button" onClick={() => setCount((prev) => prev + 1)}>
{count()}
</button>
)