New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@practicaljs/react-debounce

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@practicaljs/react-debounce

A practical package for debouncing a method.

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
1
-75%
Maintainers
2
Weekly downloads
 
Created
Source

Practical debounce

Why

Many debounce examples and packages out there contain dependencies on larger packages like lodash. While lodash has many features you don't need the extra bloat in your application.

Hook

In the example below debounce will execute your callback after a 250ms delay.

import useDebounce from "@practicaljs/react-debounce";

const { debounce } = useDebounce();

const myMethod = () => {
	debounce(() => {
		someDelayedMethodHere("test");
	}, 250);
};

If you need control over canceling the debounce, use the cancel method.

import useDebounce from "@practicaljs/react-debounce";

const { cancel } = useDebounce();

useEffect(() => {
	return () => {
		cancel();
	};
});

Component

In the example below the DebounceInput component will call the onChange method after 250ms.

import DebouncedInput from "@practicaljs/react-debounce";

const listen = (event: ChangeEvent<HTMLInputElement>) => {
	console.log(event.target.value);
};

return <DebouncedInput delay={250} onChange={listen}></DebouncedInput>;

Keywords

react

FAQs

Package last updated on 22 Dec 2022

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