useMounted

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

Demo

not mounted

Usage

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

Which is a shorthand for one of the following:

	<script lang="ts">
	import { box } from "runed";
	import { onMount } from "svelte";
 
	const isMounted = box(false);
 
	onMount(() => {
		isMounted.value = true;
	});
</script>	

or

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

© 2024 Svecosystem Team