Skip to main content
Module

x/jotai/docs/utils/use-update-atom.mdx

👻 Primitive and flexible state management for React
Go to Latest
File
---title: useUpdateAtompublished: false---
Ref: https://github.com/pmndrs/jotai/issues/26
For newer versions of Jotai you can also use [`useSetAtom`](/docs/api/core.mdx#use-set-atom) instead.
```jsximport { atom, useAtom } from 'jotai'import { useUpdateAtom } from 'jotai/utils'const countAtom = atom(0)
const Counter = () => { const [count] = useAtom(countAtom) return <div>count: {count}</div>}
const Controls = () => { const setCount = useUpdateAtom(countAtom) const inc = () => setCount((c) => c + 1) return <button onClick={inc}>+1</button>}```
<CodeSandbox id="hsyfr" />