Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

use-debounced-effect

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-debounced-effect

Debounced effect hook for react

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source

useDebouncedEffect React Hook

Install it with yarn:

yarn add use-debounced-effect

Or with npm:

npm i use-debounced-effect --save

Shorthand

useDebouncedEffect(callback, delay, dependencies)


import  React, { useState } from  'react';
import  useDebouncedEffect  from  'use-debounced-effect';

export  default  function  Input() {
	const [term, setTerm] = useState('');

	useDebouncedEffect(()=>{
	console.log(term); // debounced 1sec
	// call search api ...
	// return () => maybe cancel prev req
	}, 1000 ,[term]);

	return (
		<input  onChange={(e) => setTerm(e.target.value)}  />
	);
}

Advanced

useDebouncedEffect(callback, config, dependencies)

Config

NametypeDescriptionDefault/Fallback
delaynumberdebounce delay0
ignoreInitialCallbooleanignore first effect calltrue

Example


	useDebouncedEffect(()=>{
		console.log(term); // debounced 1sec
		// call search api ...
		// return () => maybe cancel prev req
	}, 
	{ 
		delay: 1000,
		ignoreInitialCall: false
	}
	,[term]);

}

Keywords

debounce

FAQs

Package last updated on 26 Mar 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