Playground

useDebounce

Debounced value and debounced callback: wait for input to settle before acting.

  • 2 parts, named exports
  • No DOM output. Use for search fields so the list updates after typing stops.
  • A pending callback is dropped on unmount.

Import

import '@monoline/css';
import {useDebounce} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add use-debounce

Usage

import {useState} from 'react';
import {useDebounce} from '@monoline/react';

function SearchDemo() {
  const [query, setQuery] = useState('');
  const settled = useDebounce(query, 400);
  return (
    <div>
      <label>
        Search
        <input value={query} onChange={(e) => setQuery(e.target.value)} />
      </label>
      <p>Searching for: {settled || '…'}</p>
    </div>
  );
}

<SearchDemo />

Examples

Debounced value

Updates 400 ms after you stop typing.

Props

UseDebouncedCallbackReturn

PropTypeDefaultDescription
call required(...args: A) => void–Schedules `fn` to run `delay` ms after the last call.
cancel required() => void–Drops the pending call, if any.

Behaviour

  • No DOM output. Use for search fields so the list updates after typing stops.
  • A pending callback is dropped on unmount.