Skip to content

Returning $state from a $derived should not be allowed? #15142

Answered by brunnerh
RuthgerD asked this question in Q&A
Discussion options

You must be logged in to vote

Edit: Starting with Svelte 5.25.0, it is possible to write to $derived variables declared with let.


If you need something to update when a dependency changes and also be reactive locally, this is a reasonable thing to do. If the alternative would be using an $effect, then maybe this would even be recommended.

With proxied state, this can additionally be simplified to:

let derived_state = $derived.by(() => {
    let state = $state({ current: dep });
    return state;
});

Replies: 1 comment

Comment options

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