useDebounce

About

Debounce hook for react. Internally, it uses lodash debounce.

Examples

import React, { useState } from "react";
import { useDebounce } from "rooks";

export default function App() {
  const [value, setValue] = useState("");
  const setValueDebounced = useDebounce(setValue, 500);

  return (
    <div>
      <input
        onChange={e => setValueDebounced(e.target.value)}
        placeholder="Please type here"
      />
      <div>{value}</div>
    </div>
  );
}

Arguments

ArgumentTypeDescriptionDefault value
callbackFunctionThe function to debounceundefined
waitnumberThe duration to debounce in millisecondsundefined
optionsObjectoptions to pass into lodash's debounce

Return Value

NameTypeDescription
debouncedFunctionFunctionThe debounced function

Join the community!

Join our discord server! You can click the floating discord icon at the bottom right of the screen and chat with us!

Powered by vercel