Skip to content

Patterns for updating "sync" atoms that depend on async atoms like in V1 #2003

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

You must be logged in to vote

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 and value property on fulfillment.

type PromiseMeta<T> = {
status?: 'pending' | 'fulfilled' | 'rejected'
value?: T
reason?: AnyError
orig?: PromiseLike<T>
}

Replies: 2 comments 15 replies

Comment options

You must be logged in to vote
12 replies
@Pinpickle
Comment options

@dai-shi
Comment options

@Pinpickle
Comment options

@pabo
Comment options

@dai-shi
Comment options

Answer selected by Pinpickle
Comment options

You must be logged in to vote
3 replies
@stevemolitor
Comment options

@Pinpickle
Comment options

@simon3495
Comment options

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