Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.5K
increased by40.52%
Maintainers
1
Weekly downloads
 
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

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

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