useThrottle

A higher-order function that throttles the execution of a function.

Demo

Search for something above!

Usage

	<script lang="ts">
  import { useThrottle } from "runed";
 
  import { Label } from "../ui/label";
  import DemoContainer from "$lib/components/demo-container.svelte";
  import Input from "$lib/components/ui/input/input.svelte";
 
  let search = $state("");
  let throttledSearch = $state("");
  let durationMs = $state(1000);
 
  const throttledUpdate = useThrottle(
    () => {
      throttledSearch = search;
    },
    () => durationMs
  );
 
  $effect(() => {
    search;
    throttledUpdate();
  });
</script>
 
<div>
  <input bind:value={search} />
  <p>You searched for: <b>{throttledSearch}</b></p>
</div>	
MIT

© 2024 Svecosystem Team