Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

use-debouncy

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-debouncy

๐ŸŒ€ Small (~0.2kb) debounce effect hook for React with TypeScript support

  • 5.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

useDebouncy

๐ŸŒ€ Small (~0.2kb) debounce effect hook for React with TypeScript support

GitHub npm bundle size npm types codecov FOSSA Status

Features

  • ๐Ÿ‘Œ No dependencies.
  • ๐Ÿ‹๏ธโ€ Tiny. ~0.2kb.
  • ๐Ÿฆพ Performance. Used by requestAnimationFrame.
  • ๐Ÿ“– Types. Support TypeScript.
  • ๐ŸŽฃ Easy. Use like React effect or function.

Installation

NPM
npm install use-debouncy
Yarn
yarn add use-debouncy

Usage

Demo codesandbox

Use as effect hook

import React, { useState } from 'react';
import { useDebouncyEffect } from 'use-debouncy';

const App = () => {
  const [value, setValue] = useState('');

  useDebouncyEffect(
    () => fetchData(value), // function debounce
    400, // number of milliseconds to delay
    [value], // array values that the debounce depends (like as useEffect)
  );

  return <input value={value} onChange={(event) => setValue(event.target.value)} />;
};

Use as callback function

import React, { useState } from 'react';
import { useDebouncyFn } from 'use-debouncy';

const App = () => {
  const handleChange = useDebouncyFn(
    (event) => fetchData(event.target.value), // function debounce
    400, // number of milliseconds to delay
  );

  return <input value={value} onChange={handleChange} />;
};

API Reference

useDebouncy/effect

function useDebouncyEffect(fn: () => void, wait?: number, deps?: any[]): void;
PropRequiredDefaultDescription
fnโœ“Debounce callback.
wait0Number of milliseconds to delay.
deps[]Array values that the debounce depends (like as useEffect).

useDebouncy/fn

function useDebouncyFn(fn: (...args: any[]) => void, wait?: number): (...args: any[]) => void;
PropRequiredDefaultDescription
fnโœ“Debounce handler.
wait0Number of milliseconds to delay.

Development

js-standard-style

License

FOSSA Status

Keywords

FAQs

Package last updated on 24 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc