useMounted

Reactive isMounted variable.

Usage #

  • Svelte
<script lang="ts">
import { useMounted } from 'sveltuse'

const isMounted = useMounted()
</script>

{#if $isMounted}
   <div>
      Component is mounted
   </div>
{/if}

Which is essentially a shorthand of:

import { onMount } from 'svelte'

let isMounted = false

onMount(() => {
	isMounted = true
})

Source #