🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

react-debounce-input

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-debounce-input

React component that renders Input with debounced onChange

3.3.0
latest
Source
npm
Version published
Weekly downloads
474K
4.18%
Maintainers
1
Weekly downloads
 
Created

What is react-debounce-input?

The react-debounce-input package provides a React component that debounces the input value change events. This is useful for scenarios where you want to limit the rate at which a function is executed, such as when making API calls based on user input.

What are react-debounce-input's main functionalities?

Basic Debounced Input

This example demonstrates a basic usage of the DebounceInput component. The input value is debounced with a timeout of 300 milliseconds, meaning the onChange event will only be triggered if the user stops typing for 300 milliseconds.

import React, { useState } from 'react';
import { DebounceInput } from 'react-debounce-input';

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

  return (
    <div>
      <DebounceInput
        minLength={2}
        debounceTimeout={300}
        onChange={(event) => setValue(event.target.value)}
      />
      <p>Value: {value}</p>
    </div>
  );
}

export default App;

Debounced Input with Min Length

This example shows how to use the DebounceInput component with a minimum length requirement. The onChange event will only be triggered if the input value has at least 5 characters and the user stops typing for 500 milliseconds.

import React, { useState } from 'react';
import { DebounceInput } from 'react-debounce-input';

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

  return (
    <div>
      <DebounceInput
        minLength={5}
        debounceTimeout={500}
        onChange={(event) => setValue(event.target.value)}
      />
      <p>Value: {value}</p>
    </div>
  );
}

export default App;

Debounced Input with Element

This example demonstrates how to use the DebounceInput component with a different HTML element, such as a textarea. The input value is debounced with a timeout of 300 milliseconds.

import React, { useState } from 'react';
import { DebounceInput } from 'react-debounce-input';

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

  return (
    <div>
      <DebounceInput
        element="textarea"
        minLength={2}
        debounceTimeout={300}
        onChange={(event) => setValue(event.target.value)}
      />
      <p>Value: {value}</p>
    </div>
  );
}

export default App;

Other packages similar to react-debounce-input

Keywords

component

FAQs

Package last updated on 06 Jun 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