Basic Atom

1
/
10
import { Atom, useAtom } from "@effect-atom/atom-react"

const countAtom = Atom.make(0)

export function Counter() {
  const [count, setCount] = useAtom(countAtom)

  return (
    <div>
      <div>{count}</div>
      <button onClick={() => setCount((c) => c - 1)}>
        Decrease
      </button>
      <button onClick={() => setCount(0)}>
        Reset
      </button>
      <button onClick={() => setCount((c) => c + 1)}>
        Increase
      </button>
    </div>
  )
}
Writable
0