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);
	function increment() {
		count++;
	}
 
	let wrapper = $state<HTMLElement>();
	useEventListener(() => wrapper, "click", increment);
</script>
 
<div bind:this={wrapper}>
	<p>You've clicked {count} {count === 1 ? "time" : "times"}</p>
</div>	
MIT

© 2024 Svecosystem Team