@tianrang-sz/react-hooks
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

react hooks

useDebounce react hook

Install it with yarn:

yarn add @tianrang-sz/react-hooks

Or with npm:

npm i @tianrang-sz/react-hooks --save

simple demo

import { useDebounce } from '@tianrang-sz/react-hooks';

function Input({ defaultValue }) {
  const [value, setValue] = useState(defaultValue);
  // Debounce callback
  const [debouncedCallback] = useDebounce(
    // function
    value => {
      setValue(value);
    },
    // delay in ms
    1000
  );

  // you should use `e => debouncedCallback(e.target.value)` as react works with synthetic evens
  return (
    <div>
      <input
        defaultValue={defaultValue}
        onChange={e => debouncedCallback(e.target.value)}
      />
      <p>Debounced value: {value}</p>
    </div>
  );
}

Package Sidebar

Install

npm i @tianrang-sz/react-hooks

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

4.41 kB

Total Files

11

Last publish

Collaborators

  • lbx18829292624
  • pengfei.wang