useThrottle
A higher-order function that throttles the execution of a function.
Demo
Search for something above!
Usage
<script lang="ts">
import { useThrottle, watch } from "runed";
let search = $state("");
let throttledSearch = $state("");
let durationMs = $state(1000);
const throttledUpdate = useThrottle(
() => {
throttledSearch = search;
},
() => durationMs
);
</script>
<div>
<input
bind:value={
() => search,
(v) => {
search = v;
throttledUpdate();
}
} />
<p>You searched for: <b>{throttledSearch}</b></p>
</div>