function useAtom<TValue>(atom, options?): [Accessor<TValue>, (fn) => void & (value) => void];
function useAtom<TValue>(atom, options?): [Accessor<TValue>, (fn) => void & (value) => void];
Defined in: solid-store/src/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.
TValue
Atom<TValue>
UseSelectorOptions<TValue>
[Accessor<TValue>, (fn) => void & (value) => void]
const [count, setCount] = useAtom(countAtom)
return (
<button type="button" onClick={() => setCount((prev) => prev + 1)}>
{count()}
</button>
)
const [count, setCount] = useAtom(countAtom)
return (
<button type="button" onClick={() => setCount((prev) => prev + 1)}>
{count()}
</button>
)
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.