Skip to content

Instantly share code, notes, and snippets.

@helabenkhalfallah
Created April 10, 2024 18:56
Show Gist options
  • Save helabenkhalfallah/73818c5c25506a8e3cd7df9a84caa139 to your computer and use it in GitHub Desktop.
Save helabenkhalfallah/73818c5c25506a8e3cd7df9a84caa139 to your computer and use it in GitHub Desktop.
Svelte Life Cycle
<script>
import { afterUpdate, beforeUpdate, onDestroy, onMount, tick } from 'svelte';
onMount(() => {
console.log('the component has mounted');
});
beforeUpdate(() => {
console.log('the component is about to update');
});
afterUpdate(() => {
console.log('the component just updated');
});
onDestroy(() => {
console.log('the component is being destroyed');
});
beforeUpdate(async () => {
console.log('the component is about to update');
await tick();
console.log('the component just updated');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment