Recall & Review
beginner
What is the purpose of the
onMount lifecycle function in Svelte?The
onMount function runs after the component is first added to the page. It is used to run code that needs the component to be visible, like fetching data or setting up event listeners.Click to reveal answer
intermediate
How do nested components affect lifecycle execution order in Svelte?
Child components mount first, then their parent components mount. When unmounting, children are removed before their parents. This order ensures children are ready when parents finish mounting.
Click to reveal answer
beginner
What lifecycle function should you use to clean up resources in a Svelte component?
Use the function returned by
onMount or the onDestroy lifecycle function to clean up resources like timers or event listeners when the component is removed.Click to reveal answer
intermediate
In nested Svelte components, when does the
onDestroy lifecycle function run?The
onDestroy function runs when a component is removed from the page. For nested components, children run their onDestroy before their parents do.Click to reveal answer
intermediate
Why is understanding lifecycle order important in nested Svelte components?
Knowing lifecycle order helps avoid bugs like trying to use a child component before it exists or cleaning up resources too late. It ensures smooth setup and teardown of components.
Click to reveal answer
In Svelte, which lifecycle function runs first when a nested component is added to the page?
✗ Incorrect
The child component's onMount runs first, then the parent component's onMount.
Which lifecycle function is best for cleaning up event listeners in a Svelte component?
✗ Incorrect
The onDestroy function runs when the component is removed and is the right place to clean up event listeners.
When a parent Svelte component is removed, what happens first?
✗ Incorrect
Children run their onDestroy before their parents to ensure proper cleanup.
What does the
onMount lifecycle function in Svelte NOT do?✗ Incorrect
Cleaning up event listeners is done in onDestroy, not onMount.
Why should you be careful about lifecycle order in nested components?
✗ Incorrect
Understanding lifecycle order helps avoid bugs like using child components before they are ready.
Explain the order of lifecycle functions when mounting and unmounting nested components in Svelte.
Think about who comes first when adding and removing components.
You got /4 concepts.
Describe how to properly clean up resources like event listeners in nested Svelte components.
Focus on the lifecycle function that runs when components are removed.
You got /4 concepts.