-
(This description will be updated over time. Please quote sentences when you add comments.) BackgroundJotai is designed to fully support Concurrent React and Suspense for data fetching. Other than the implementation complexity, there are some issues:
Furthermore, the biggest change recently is the use RFC. It indicates that throwing promises in a library is no longer supported (which is never supported), and needs Why this changeWhen we released Jotai v1, we knew Suspense for data fetching is unstable. Our hope was, when it's finalized, we update our implementation with keeping Jotai v1 API. It might be still possible, but as we see the use RFC, the general preference we should follow is async/await, not throwing promises behind the scene. So, we propose new Jotai v2 API. It will become more compatible with What will be breakingAfter spending days and weeks, our conclusion is that this API is breaking change for async usage. // Current API
const asyncAtom = atom(async () => 'hello')
const derivedAtom = atom((get) => get(asyncAtom).toUppercase())
// New API
const asyncAtom = atom(async () => 'hello')
const derivedAtom = atom(async (get) => (await get(asyncAtom)).toUppercase()) This can be said a behavioral change, but the new type definition is different and incompatible with the current one. By the way, there's a big benefit with the current API. Not only it can skip async/await syntax, it can skip extra computation. It should perform well with Concurrent React too. But, for most cases, the new API should work well. We will also make Even though the current // Current API
import { atom } from 'jotai'
// New API
import { atom } from 'jotai/vanilla' (We might be able to expose the new API from Other major changes
Release plan
Open problems
Alternatives
|
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 23 replies
-
Building for the future is always better since React is taking a big move here with "use" and async/await, so moving directly to v2 is a better option i guess while the changes are not that big. |
Beta Was this translation helpful? Give feedback.
-
Hm, it might not be a good idea to have the prefix, because people have to modify it again. Probably, we should simply document it while it's "unstable". |
Beta Was this translation helpful? Give feedback.
-
I wonder if it will be possible to |
Beta Was this translation helpful? Give feedback.
-
Moving directly to v2 is a better option in my opinion as well. |
Beta Was this translation helpful? Give feedback.
-
That's the problem with the current library, what we can do with the gradual API changes, is provide utils (in jotai-labs hopefully) for other component libraries, so we can gradually remove the notion of jotai being tied to React. So we would achieve the title of "Jotai: the framework-agnostic state-management library". |
Beta Was this translation helpful? Give feedback.
-
Can you imagine when would be v2 release? |
Beta Was this translation helpful? Give feedback.
-
One problem I found when experimenting with v2 api is that:
One example is an in-memory cache that loads something and then operates on it synchronously: const asyncAtom = atom(Promise.resolve("test"));
const derivedAtom = atom(async (get) => {
return get(asyncAtom)
}, (get, set, update) => {
// every write will suspend for a fraction of a second although asyncAtom doesn't have a promise anymore
set(asyncAtom, update)
}) What is the correct way to make mixed atoms that may or may not suspend? |
Beta Was this translation helpful? Give feedback.
-
Thanks for this! Was able to experiment on a solid port with suspense working- https://github.com/wobsoriano/solid-jotai |
Beta Was this translation helpful? Give feedback.
-
I'm giving v2 a try and I would love to know how can I initialize the Provider store with some data, within the react render cycle? All examples I see in https://github.com/pmndrs/jotai/blob/main/tests/react/provider.test.tsx are setting the values outside of the rendering:
But I'd love to do something like:
|
Beta Was this translation helpful? Give feedback.
-
Hi @dai-shi. I have a question about the result of an atom writer:
In a discussion a few weeks ago you said that the setter is not guaranteed to run in the same frame. |
Beta Was this translation helpful? Give feedback.
-
Glad to see this. What i proposed here #1219 (comment) |
Beta Was this translation helpful? Give feedback.
-
I don't see it mentioned anywhere that |
Beta Was this translation helpful? Give feedback.
#1515 The first PR
#1671 Probably the last