Trap suggestions in use:
documentation
#15390
Fd929c2CE5fA
started this conversation in
General
Replies: 1 comment 1 reply
-
I would recommend directly opening an issue if you think some aspect of the docs is incomplete or can be improved. Regarding $effect(() => console.log("update-$effect", count1));
$effect(() => {
return () => {
console.log("destroy-$effect", count1);
count1 = 0;
}
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
https://svelte.dev/docs/svelte/use
According to the Svelte 5 documentation's description of
use:
, it implies thatreturn {update, destroy}
is replaced by$effect
.https://svelte.dev/docs/svelte/$effect
But in fact, according to the documentation for
$effect
, the return in$effect
actually runs when it is destroyed and effect re-runs.It is different from destroy behavior in
use:
return, cannot be replaced directly, and may cause unexpected behavior.When the expected
destroy
is only run when the element is destroyed, using$effect
as recommended may lead to unexpected behavior.Here is an example of the different behaviors of the two: Playground
Beta Was this translation helpful? Give feedback.
All reactions