Skip to content

promises, suspense, and changing params #132

Answered by bowheart
joprice asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @joprice. Components using any atom hooks will re-suspend when the atom's .promise reference changes.

const suspendingAtom = atom('suspending', () => {
  // quick example that changes the promise reference every time this atom reevaluates:
  return api().setPromise(new Promise(resolve => setTimeout(() => resolve('test'), 1000))))
})

function ExampleComponent() {
  const suspendingInstance = useAtomInstance(suspendingAtom)

  return <button onClick={() => suspendingInstance.invalidate()}>Re-suspend</button>
}

function ExampleSuspenseWrapper() {
  return (
    <Suspense fallback={<div>ExampleComponent suspending...</div>}>
      <ExampleComponent />
    <Suspense>
  )
}

Note that you …

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@bowheart
Comment options

@joprice
Comment options

@joprice
Comment options

@bowheart
Comment options

@joprice
Comment options

Answer selected by joprice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants