Complete the code to run a function when the component is first added to the page.
<script> import { [1] } from 'svelte'; onMount(() => { console.log('Component mounted'); }); </script>
The onMount function runs code when the component is first added to the page.
Complete the code to clean up when a nested component is removed.
<script> import { onDestroy } from 'svelte'; onDestroy(() => { [1]; }); </script>
The onDestroy function runs cleanup code when the component is removed from the page.
Fix the error in the nested component lifecycle hook usage.
<script> import { onMount } from 'svelte'; onMount(() => { console.log('Nested component [1]'); }); </script>
The onMount hook runs when the component is mounted, so the message should say 'mounted'.
Fill both blanks to run code before and after the component updates.
<script> import { [1], [2] } from 'svelte'; [1](() => { console.log('Before update'); }); [2](() => { console.log('After update'); }); </script>
beforeUpdate runs code before the component updates, and afterUpdate runs code after the update.
Fill all three blanks to correctly handle lifecycle in a nested component.
<script> import { [1], [2], [3] } from 'svelte'; [1](() => { console.log('Mounted'); }); [2](() => { console.log('Before update'); }); [3](() => { console.log('Cleanup on destroy'); }); </script>
onMount runs when the component appears, beforeUpdate runs before changes, and onDestroy runs cleanup when removed.