-
consider the following code: let dep = $state(123)
let derived_state = $derived.by(() => {
let state = $state(dep)
return { get current() { return state }, set current(value) { state = value } }
})
derived_state.current = 456 can I get someone to clarify if this is encouraged or not |
Beta Was this translation helpful? Give feedback.
Answered by
brunnerh
Jan 29, 2025
Replies: 1 comment
-
Edit: Starting with Svelte 5.25.0, it is possible to write to 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 With proxied state, this can additionally be simplified to: let derived_state = $derived.by(() => {
let state = $state({ current: dep });
return state;
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
RuthgerD
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edit: Starting with Svelte 5.25.0, it is possible to write to
$derived
variables declared withlet
.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: