Help! The onMount fires when $data from API hasn't yet returned into a writable store, shall I use a callback? #11208
federicomarcantognini
started this conversation in
General
Replies: 2 comments
-
Can you share code to show what you are trying to build - then it's much more easy to help answer your questions :) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Instead of using onMount, you can call the function when the data is updated like: $: $data, init();
const init = () => {
if ($data) {
// $data is not undefined here
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When I use a writable store into the onMount in a component, the onMount fires when the data is not yet resolved from my API, therefore $data is still empty when onMount fires.
How to ensure that $data is populated from API response right into onMount? A callback?
Many thanks in advance and apologies for the silly question
Beta Was this translation helpful? Give feedback.
All reactions