Skip to content

Instantly share code, notes, and snippets.

@muhibbudins
Last active July 28, 2019 03:20
Show Gist options
  • Save muhibbudins/d36d0d88cbbdbae21c78f542c3e9c289 to your computer and use it in GitHub Desktop.
Save muhibbudins/d36d0d88cbbdbae21c78f542c3e9c289 to your computer and use it in GitHub Desktop.
<script>
import {
onMount,
tick,
beforeUpdate,
afterUpdate,
onDestroy
} from 'svelte'
let photos = []
// Dijalankan setelah halaman di buat
onMount(async () => {
const res = await fetch('...')
photos = await res.json()
// Menunggu suatu proses yang belum selesai
await tick()
// do something here
})
// Dijalankan ketika komponen akan di buat
beforeUpdate(() => {
// do something here
})
// Dijalankan ketika komponen telah di buat dan di sync dengan data
afterUpdate(() => {
// do something here
})
// Dijalankan setelah komponen di hapus dari halaman
onDestroy(() => {
photos = []
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment