Will a $derived in a context propagate reactive changes? LSP doesn't think so...
#17134
-
|
I put a Is this intended? I would have expected the changes to propagate... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
This is just how variables work in JS: You pass in whatever the variable references at that point in time. The solution is usually to pass a stateful object into the context, that way, the reactivity is contained within the object. Any mutation of properties can be reacted to. If you need to pass a let value = $derived(...);
setContext('key', () => value);
// or
setContext('key', {
get value() { return value; }
});Both of these reference the variable rather than taking the current value directly. |
Beta Was this translation helpful? Give feedback.
This is just how variables work in JS: You pass in whatever the variable references at that point in time.
If the variable changes later, the function you passed the value to will not know about it.
The solution is usually to pass a stateful object into the context, that way, the reactivity is contained within the object. Any mutation of properties can be reacted to.
If you need to pass a
$derived, you can close over it, e.g.Both of these reference the variable rather than taking the current value directly.