Complete the code to run a function when the component is first added to the page.
import { onMount } from 'svelte'; onMount(() => { console.log([1]); });
The onMount hook runs the code inside its function when the component appears on the page. We pass a string message to console.log to show it.
Complete the code to clean up when the component is removed from the page.
import { onDestroy } from 'svelte'; onDestroy(() => { [1]; });
onDestroy inside itself.The onDestroy hook runs when the component is removed. We use console.log with a string message inside quotes to show cleanup.
Fix the error in the code to run code after the component updates.
import { afterUpdate } from 'svelte'; afterUpdate(() => { console.log([1]); });
afterUpdate inside itself.The afterUpdate hook runs after the component changes. The message must be a string inside quotes for console.log.
Fill both blanks to run code when the component mounts and cleans up when it is destroyed.
import { [1], [2] } from 'svelte'; [1](() => { console.log('Mounted'); }); [2](() => { console.log('Destroyed'); });
onMount and onDestroy.onMount runs code when the component appears, and onDestroy runs code when it is removed. Import and use both to handle these moments.
Fill all three blanks to log messages at mount, update, and destroy lifecycle moments.
import { [1], [2], [3] } from 'svelte'; [1](() => { console.log('Mounted'); }); [2](() => { console.log('Updated'); }); [3](() => { console.log('Destroyed'); });
beforeUpdate with afterUpdate.Use onMount to run code when the component loads, afterUpdate after it changes, and onDestroy when it is removed.