Skip to content

Latest commit

History

History
26 lines (21 loc) 路 487 Bytes

use-atom-value.mdx

File metadata and controls

26 lines (21 loc) 路 487 Bytes
title published
useAtomValue
false

Ref: #212

import { atom, Provider, useAtom } from 'jotai'
import { useAtomValue } from 'jotai/utils'

const countAtom = atom(0)

const Counter = () => {
  const setCount = useUpdateAtom(countAtom)
  const count = useAtomValue(countAtom)
  return (
    <>
      <div>count: {count}</div>
      <button onClick={() => setCount(count + 1)}>+1</button>
    </>
  )
}