Skip to content
Discussion options

You must be logged in to vote

No built-in option for this right now. Your $effect + $state combo is the intended way to handle "render immediately, update when ready."

The await in $derived is designed to block on purpose — it guarantees the value is always resolved when you read it, which is useful but obviously not what you want when you need to show a loading state.

If you find yourself repeating this pattern, you could extract it:

function lazyAsync(fn) {
  let value = $state();
  $effect(() => {
    fn().then(v => value = v);
  });
  return () => value;
}

// usage
const data = lazyAsync(() => promise);
// read with data()

But honestly for a one-off, your current code is fine and readable. There's been some discu…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Profiidev
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants