Skip to content

Unwrapped Atom Always Returns undefined on First Read After v2.10 Update #2877

Answered by dai-shi
ics-matsumoto asked this question in Q&A
Discussion options

You must be logged in to vote

From the code and test changes, this seems to be an intentional change, not a bug

Yeah, it's intentional.

However, I couldn't find any explanation for this change.

I'm sorry. It's not described well. The rationale is that our store implementation shouldn't deal with promises. It's the core principle of Jotai v2 actually.

unwrap doesn't do a magic now. It takes one tick to resolve a promise. So you should basically prepare for undefined even if it's Promise.resolve(0).

I wonder if this works for your case.

const checkValueAtom = atom(undefined, async (get) => {
  const value = await get(asyncValueAtom);
  console.log(value ? "value is ready" : "value is not ready");
});

Is this behavi…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@dmaskasky
Comment options

@dai-shi
Comment options

Comment options

You must be logged in to vote
2 replies
@dmaskasky
Comment options

@ics-matsumoto
Comment options

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