-
Follow up to #142 I'm having an issue where I'd like for my store to initialize with data from an asynchronous request, and suspend the application until this data is available. I created this sandbox to demonstrate the error. It could be I'm missing something obvious, or I'm not understanding the suspense/asynchronous behavior. Please Use Proxy Object Error Example Two main issues (I think are probably the same issue):
Requirements 2 works if I pass the entire store as a prop, and then index in to the 'requirements' object. It's responsive and reacts, but I'm passing more data down than I want. It then fails when trying to create a child component using its data as a prop. Your help is appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Okay, so if you put a promise in a proxy state, it's just a promise. Even if the promise is resolved, what you get is the promise, not the resolved value. const state = proxy({ promise: Promise.resolve({ name: 'hello' }) })
state.promise // is a promise
state.promise.name // is thus `undefined` When you use const state = proxy({ promise: Promise.resolve({ name: 'hello' }) })
const snap = useSnapshot(state)
snap.promise // is *not* a promise
snap.promise.name // is 'hello' |
Beta Was this translation helpful? Give feedback.
Okay, so if you put a promise in a proxy state, it's just a promise. Even if the promise is resolved, what you get is the promise, not the resolved value.
When you use
useSnapshot
(orsnapshot
), you get the resolved value (or thrown if it's not ready).