Skip to content

reset state without using $effect? #16206

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

You must be logged in to vote

If you want deep reactivity on the items you would need to wrap the array in $state.
This also splits logic that is coupled, so I probably would not go with this if events or function bindings cannot be used. (You could maybe bundle both variables into a single object, though that might not be the logical thing to do depending on context.)

Note that just using an $effect for this is really is not much of an issue. For certain things, like synchronizing a local, mutable variable from a prop, $effect has actually been recommended for some time (now that $derived can be overwritten, you don't need that any more).

So compared to the $derived approach, I find the $effect code to be cleaner, an…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@MihailsKuzmins
Comment options

@brunnerh
Comment options

Answer selected by MihailsKuzmins
@MihailsKuzmins
Comment options

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