UseEventListener

A function that attaches an automatically disposed event listener.

Demo

You've clicked 0 Times

Usage

	<script lang="ts">
	import { useEventListener } from "runed";
 
	let count = $state(0);
 
	$effect(() => {
		useEventListener(document, "click", () => count++);
	});
</script>
 
<div class="rounded-md bg-card p-8">
	<p>You've clicked {count} {count === 1 ? "Time" : "Times"}</p>
</div>	
MIT

© 2024 Svecosystem Team