-
I'd like to set an initial state to a value from my server. If there's an error, I'd like the value to be [].
But I'd also like the value to be [] until the promise resolves. The docs mention that I can use React Suspense to handle pending data. So I suppose I could do something like
But I was wondering if there was any other way to do this outside the component? Maybe inside the atom itself? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, if you initialize atom state with Atom Effects you can either initialize with a promise so it starts in a pending state, or you can use this pattern to have it start with the default value and when the data is asynchronously ready then update the atom value. |
Beta Was this translation helpful? Give feedback.
Yes, if you initialize atom state with Atom Effects you can either initialize with a promise so it starts in a pending state, or you can use this pattern to have it start with the default value and when the data is asynchronously ready then update the atom value.