Atom
⚠️
<Atom/>
is experimental feature, this interfaces could be changed
The Atom component provides the same props interface as Jotai's useAtom (opens in a new tab) hook and can be used declaratively.
props.atom
The atom prop behaves the same as Jotai's atom interface.
import { Atom } from '@suspensive/jotai'
import { atom } from "jotai";
const countAtom = atom(1);
const Example = () => (
<Atom atom={countAtom}>
{([count, setCount]) => (
<>
<div>count: {count}</div>
<button onClick={() => setCount(count + 1)}>+1</button>
</>
)}
</Atom>
)
For async atoms, you can handle the loading state using Suspense.
import { Atom } from '@suspensive/jotai'
import { Suspense } from '@suspensive/react'
import { atom } from "jotai";
const countAtom = atom(1)
const asyncAtom = atom(async (get) => get(countAtom) * 2)
const Example = () => (
<Suspense fallback={'loading...'}>
<Atom atom={asyncAtom}>
{([count]) => (
<>count: {count}</>
)}
</Atom>
</Suspense>
)