👀 Check out the changes in Suspensive v2 read more →
Documentation
@suspensive/jotai
<AtomValue/>

AtomValue

⚠️

<AtomValue/> is experimental feature, this interfaces could be changed

The AtomValue component provides the same props interface as Jotai's useAtomValue (opens in a new tab) hook and can be used declaratively.

props.atom

You can use Jotai's atom as is.

import { AtomValue } from '@suspensive/jotai'
import { atom } from "jotai";
 
const countAtom = atom(1);
 
const Example = () => (
  <AtomValue atom={countAtom}>
    {(count) => (
      <>count: {count}</>
    )}
  </AtomValue>
)

For Async Atom, you can handle the loading state using Suspense.

import { AtomValue } from '@suspensive/jotai'
import { Suspense } from '@suspensive/react'
import { atom } from "jotai";
 
const countAtom = atom(1)
const asyncDoubleCountAtom = atom(async (get) => {
  await delay(2000)
  return get(countAtom) * 2
})
 
const Example = () => (
  <Suspense fallback={'pending...'}>
    <AtomValue atom={asyncDoubleCountAtom}>
      {(count) => (
        <>count: {count}</>
      )}
    </AtomValue>
  </Suspense>
)