question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setting an atom with a promise results in `deleting atomState with read promise` error

See original GitHub issue

I put together an example here:

https://github.com/zcaudate/js-blessed.store-test

but basically I’m getting an error when using atoms with Suspense.

I’d like to be able to have an atom that is initialised with nil, can have a promise resolving to some data and then be reset back to nil.

So in the example, the atom’s initial value is null. createRecord is basically create atom with some metadata stuffed into it:

Then I set the atom’s value to a promise (which resolves after a time out) and it produces this error in the suspense element:

// React will try to recreate this component tree from scratch using the error boundary you provided, Debug.
[Bug] deleting atomState with read promise {
  toString: [Function: toString],
  init: null,
  read: [Function (anonymous)],
  write: [Function (anonymous)],
  id: 'js-blessed.store-test.main/UserData',
  section: 'js-blessed.store-test.main/User'
}

This is a bug or a feature of atoms in jotai and if it’s a feature, how do I implement a resettable atom with a promise?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
zcaudatecommented, May 14, 2021

thanks for your help!

0reactions
zcaudatecommented, May 14, 2021

okay. this actually works on the dom:

https://codesandbox.io/s/react-typescript-forked-813p1?file=/src/App.tsx

It must be an issue with the react-blessed renderer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling with promises - The Modern JavaScript Tutorial
Promise chains are great at error handling. When a promise rejects, the control jumps to the closest rejection handler.
Read more >
Asynchronous Data Queries - Recoil
Simply return a Promise to a value instead of the value itself from a ... with synchronous atom state, derived selector state, or...
Read more >
React + Recoil - Set atom state after async HTTP GET or ...
This is a quick example of how to set the state of a Recoil atom after sending an async HTTP GET or POST...
Read more >
Simplifying your application state management with Recoil
A hook that returns the current atom or selector value. This hook is intended to use when you only need to read the...
Read more >
TanStack Query - Jotai
The second one is called statusAtom and it's an atom for the full result from ... A query can be used with any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found