Svelte · Junior · Question 46 of 76

How do you add a listener to window from a component?

Explanation

Svelte adds and removes the listener with the component lifecycle and it's safe during SSR. You can also bind innerWidth, scrollY and similar values.

Further reading

Problem with a question

Svelte · Junior · question 46

Test yourself

Take the Svelte · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz