Recall & Review
beginner
What is a lifecycle hook in Svelte?
A lifecycle hook is a special function that runs code at important times during a component's life, like when it starts, updates, or stops.
Click to reveal answer
beginner
Why do we use the
onMount lifecycle hook?onMount runs code right after the component appears on the screen. It's useful for starting tasks like fetching data or setting up timers.Click to reveal answer
intermediate
What does the
beforeUpdate hook do?beforeUpdate runs code just before the component updates its content on the screen. It helps prepare or check things before the change happens.Click to reveal answer
intermediate
How does the
onDestroy hook help with cleanup?onDestroy runs code when the component is removed from the screen. It helps stop timers, remove event listeners, or free resources to keep the app fast and clean.Click to reveal answer
beginner
Why is it important to run code at key moments in a component's life?
Running code at key moments helps the app stay organized, efficient, and responsive. It makes sure things start, update, and stop at the right time, like a well-timed dance.
Click to reveal answer
Which Svelte lifecycle hook runs code right after the component appears on the screen?
✗ Incorrect
onMount runs code after the component is added to the page.What is the main purpose of the
onDestroy hook?✗ Incorrect
onDestroy helps clean up things like timers and event listeners when the component is removed.When does the
beforeUpdate hook run?✗ Incorrect
beforeUpdate runs just before the component changes on the screen.Why are lifecycle hooks useful in Svelte components?
✗ Incorrect
Lifecycle hooks let you run code exactly when the component starts, updates, or stops.
Which hook would you use to fetch data when a component first appears?
✗ Incorrect
onMount is the right place to start tasks like fetching data when the component loads.Explain why lifecycle hooks are important in Svelte components and give examples of when you might use them.
Think about what happens when a component starts, changes, or stops.
You got /3 concepts.
Describe the difference between
beforeUpdate and afterUpdate hooks in Svelte.Consider when you want to prepare for or respond to updates.
You got /3 concepts.