IsMounted

A class that returns the mounted state of the component it's called in.

Demo

Mounted: false

Usage

	<script lang="ts">
  import { IsMounted } from "runed";
 
  const isMounted = new IsMounted();
</script>	

Which is a shorthand for one of the following:

	<script lang="ts">
  import { onMount } from "svelte";
 
  const isMounted = $state({ current: false });
 
  onMount(() => {
    isMounted.current = true;
  });
</script>	

or

	<script lang="ts">
  import { untrack } from "svelte";
 
  const isMounted = $state({ current: false });
 
  $effect(() => {
    untrack(() => (isMounted.current = true));
  });
</script>	
MIT

© 2024 Svecosystem Team