Svelte · Middle · Question 56 of 75
What is wrong with this $effect?
$effect(() => {
if (browser) {
window.addEventListener("resize", onResize);
}
});- ✓Correct answer: The
browsercheck is unnecessary (effects never run on the server), and there's no cleanup; better use<svelte:window onresize> - 2
windowcan't be accessed in effects - 3Nothing
Explanation
<svelte:window> adds and removes the listener for you. If you do use an effect, return a function that removes the listener.