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

@react-hook/debounce

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-hook/debounce

A React hook for debouncing setState and other callbacks

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
179K
decreased by-13.69%
Maintainers
1
Weekly downloads
 
Created

What is @react-hook/debounce?

@react-hook/debounce is a React hook library that provides a simple way to debounce values and functions. Debouncing is a technique used to limit the rate at which a function is executed, ensuring that it is only called after a certain amount of time has passed since the last call. This is particularly useful for optimizing performance in scenarios like handling user input, API calls, and other events that can trigger frequent updates.

What are @react-hook/debounce's main functionalities?

Debouncing a value

This feature allows you to debounce a value, ensuring that the value is only updated after a specified delay. In this example, the `useDebounce` hook is used to debounce the `value` state, and the debounced value is logged to the console.

```javascript
import { useDebounce } from '@react-hook/debounce';

function DebouncedInput() {
  const [value, setValue] = useState('');
  const [debouncedValue] = useDebounce(value, 300);

  useEffect(() => {
    // Perform an action with the debounced value
    console.log(debouncedValue);
  }, [debouncedValue]);

  return (
    <input
      type="text"
      value={value}
      onChange={(e) => setValue(e.target.value)}
    />
  );
}
```

Debouncing a function

This feature allows you to debounce a function, ensuring that the function is only executed after a specified delay. In this example, the `useDebouncedCallback` hook is used to debounce the `handleClick` function, and the debounced function is called when the button is clicked.

```javascript
import { useDebouncedCallback } from '@react-hook/debounce';

function DebouncedButton() {
  const handleClick = () => {
    console.log('Button clicked');
  };

  const debouncedHandleClick = useDebouncedCallback(handleClick, 300);

  return (
    <button onClick={debouncedHandleClick}>
      Click me
    </button>
  );
}
```

Other packages similar to @react-hook/debounce

Keywords

FAQs

Package last updated on 18 Jun 2021

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