react-debounce-input is a React component that provides debounced `onChange` functionality for HTML input elements (like `<input>` or `<textarea>`) or any custom React component that follows the `value`/`onChange` prop pattern. It prevents excessive re-renders, state updates, or API calls during rapid user input by delaying the `onChange` callback until a specified `debounceTimeout` has elapsed since the last change. The current stable version is `3.3.0`, which added official React 18 support. The package maintains an active release cadence, addressing bug fixes, enhancing features (e.g., TypeScript support since v3.2.0, `inputRef` in v3.1.0), and keeping dependencies updated. Its primary differentiator is its straightforward, drop-in usability, enabling developers to easily integrate debouncing without writing custom logic, offering a simple alternative to more complex form libraries.
npm install react-debounce-inputVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `DebounceInput` with a functional React component, setting a minimum length and a debounce timeout. It also showcases state management for the debounced value.
Upgrade your React project to version 15.3.0 or higher. If you must support older React versions, use `react-debounce-input@2.x`.
To enable automatic debouncing, ensure `debounceTimeout` is set to a positive number (e.g., `300`). If `Enter`-only notification is intended, clearly communicate this behavior to users.
Implement checks in your `onChange` handler to gracefully manage empty string values, especially when dealing with validation or search queries that expect a minimum length.
When using `DebounceInput` with `element="textarea"`, consider explicitly setting `forceNotifyByEnter={false}` if you want `Enter` to behave as a standard newline character without forcing an `onChange` notification.Upgrade to `react-debounce-input@3.0.1` or a newer version to ensure `onBlur` and `onKeyPress` props integrate seamlessly without unintended side effects on `onChange` notification.
Ensure you are using `import { DebounceInput } from 'react-debounce-input';` to correctly import the named component.Upgrade your `react` and `react-dom` packages to a version compatible with `^15.3.0 || 16 || 17 || 18`. For example, `npm install react@18 react-dom@18`.
Ensure the `event` parameter in your `onChange` handler is correctly typed, for example: `(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => ...`.