$derived() with Promise
#14606
-
I fully expected this ⬇️ to work after reading Basic Svelte / Logic / Await blocks: x=$state()
y=$derived(<Promise>func(x)) I tired various version, see repl What am I doing wrong? N.B.: await block is not an option, as the described functionality is in a shared context object. |
Beta Was this translation helpful? Give feedback.
Answered by
brunnerh
Dec 7, 2024
Replies: 1 comment 3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your question is not particularly clear. You show a
$derived
holding a promise but your comment suggest that you don't want a promise at all but just the results of an async operation.If that is the case you need a
$state
updated via an$effect
. You could set that up in the constructor of the class if you need it to be contained. If the$effect
should be independent from any component lifetime, you will need to create an$effect.root
around it.