-
In my current project, (still on 1.X), I use this pattern where a "sync" atom depends on an async atom. It's not actually sync but once the async atom first loads it effectively is. Something like this:
Once In V2, there's no special suspense inside atoms, so async atoms are just promises. This means that my In some cases (not all), it's trivial to wrap in a React 18 Here's a codesandbox showing what I mean: https://codesandbox.io/s/sync-and-async-atom-setting-n4g46r?file=/src/App.tsx Are there any patterns for getting the old behaviour back? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 15 replies
-
Thanks for opening the discussion. Use
|
Beta Was this translation helpful? Give feedback.
-
I recently wrote an implementation of a utility that creates an atom that:
Seems to be exactly what you were describing. It took a couple tries to implement, but it proved very useful in our project's codebase. I have a couple utils like that with interesting properties, might post them as topics here, maybe they will help others looking for these solutions. |
Beta Was this translation helpful? Give feedback.
Thanks for opening the discussion.
I've considered a lot when introducing v2 breaking changes. Unfortunately, there are no silver bullets.
There are three ways to work around your case.
Use
unstable_unwrap
This is essentially to mitigate v1 usage. It's not one-to-one, but you can get sync atom from an async atom.
Hopefully, we'll soon remove
unstable_
prefix and document it.Jotai store follows React convention for promises.
It has
status
property andvalue
property on fulfillment.jotai/src/vanilla/store.ts
Lines 38 to 43 in 2188d75