Quick Example

useThrottle Usage

ตัวอย่าง import และการใช้งานแบบสั้นสำหรับหน้า `use-throttle`

Code

                <script lang="ts">
 import { useThrottle } from 'svelora';

 const throttle = useThrottle({ delay: 200 });

 function handleScroll() {
  throttle.run(() => console.log('scroll'));
 }
</script>

<svelte:window onscroll={handleScroll} />
            

useThrottle

Cap a callback to at most once per delay, with leading and trailing invocation. The companion to useDebounce — ideal for scroll, resize, mousemove, and drag handlers.

Throttled input (delay: 300ms)

Type quickly. Unlike useDebounce (which waits for a pause), throttle updates the query at a steady rate while you type — good for live filtering.

Keystrokes: 0 Query updates: 0 Throttled value:

Mousemove rate (delay: 100ms)

Move your cursor across the box. Raw events fire on every pixel; the throttled callback runs at most ~10×/second.

Move here
Raw events: 0 Throttled runs: 0

Rapid clicks (delay: 600ms)

Click fast: the first click fires immediately (leading), then bursts collapse into one trailing call per window.