toss / suspensive

Manage asynchronous operations, timing, error handling, detecting intersection of elements, and caching easily and declaratively
https://suspensive.org
MIT License
508 stars 48 forks source link

[Feature]: @suspensive/jotai #1040

Closed manudeli closed 2 months ago

manudeli commented 3 months ago

Package Scope

etc

Description

@suspensive/jotai

AS-IS

const ComponentUsingAsyncAtoms = () => {
  const [num] = useAtom(asyncAtom)
  // here `num` is always `number` even though asyncAtom returns a Promise
}
const App = () => {
  return (
    <Suspense fallback={/* What to show while suspended */}>
      <ComponentUsingAsyncAtoms />
    </Suspense>
  )
}

Possible Solution

TO-BE

https://jotai.org/docs/guides/async

const App = () => {
  return (
    <Suspense fallback={/* What to show while suspended */}>
      <Atom {...asyncAtom}>
        {([num]) => <>...</>}
      </Atom>
    </Suspense>
  )
}

https://jotai.org/docs/extensions/query

const App = () => {
  return (
    <Suspense fallback={/* What to show while suspended */}>
      <Atom {...atomWithQuery}>
        {(query) => <>...</>}
      </Atom>
    </Suspense>
  )
}

etc.

No response