Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 470 Bytes

use-atom-value.mdx

File metadata and controls

25 lines (20 loc) · 470 Bytes
title
useAtomValue

Ref: pmndrs#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>
    </>
  )
}