React component that renders Input with debounced onChange
npm install react-debounce-input


React component that renders an Input, Textarea or other element with debounced onChange. Can be used as drop-in replacement for or
http://nkbt.github.io/react-debounce-input
http://codepen.io/nkbt/pen/VvmzLQ
``sh`
npm install --save react-debounce-input
`sh`
yarn add react-debounce-input
html
(Module exposed as DebounceInput)
`Usage
`js
import React from 'react';
import ReactDOM from 'react-dom';
import {DebounceInput} from 'react-debounce-input';class App extends React.Component {
state = {
value: ''
};
render() {
return (
minLength={2}
debounceTimeout={300}
onChange={event => this.setState({value: event.target.value})} />
Value: {this.state.value}
);
}
}const appRoot = document.createElement('div');
document.body.appendChild(appRoot);
ReactDOM.render( , appRoot);
`Options
$3
You can specify element="textarea". For Example:
`js
`Will result in
`js
`Note: when rendering a
you may wish to set forceNotifyByEnter = {false} so the user can make new lines without forcing notification of the current value.This package has only been tested with
and but should work with any element which has value and onChange props.You can also use a custom react component as the element. For Example:
`js
`Will result in
`js
`$3
Function called when value is changed (debounced) with original event passed through
$3
Value of the Input box. Can be omitted, so component works as usual non-controlled input.
$3
Minimal length of text to start notify, if value becomes shorter then
minLength (after removing some characters), there will be a notification with empty value ''.
$3
Notification debounce timeout in ms. If set to
-1, disables automatic notification completely. Notification will only happen by pressing Enter then.
$3
Notification of current value will be sent immediately by hitting
Enter key. Enabled by-default. Notification value follows the same rule as with debounced notification, so if Length is less, then minLength - empty value '' will be sent back.NOTE if
onKeyDown callback prop was present, it will be still invoked transparently.$3
Same as
forceNotifyByEnter, but notification will be sent when focus leaves the input field.$3
Will pass
ref={inputRef} to generated input element. We needed to rename ref to inputRef since ref is a special prop in React and cannot be passed to children. See ./example/Ref.js for usage example.
$3
`js
type="number"
onChange={event => this.setState({value: event.target.value})}
placeholder="Name"
className="user-name" />
`Will result in
`js
type="number"
placeholder="Name"
className="user-name" />
`Typescript
This library has typescript typings, import them the same way as in javascript:
`typescript
import {DebounceInput} from 'react-debounce-input';
`Also there are helper types
DebounceTextArea and Debounced to provide strict interfaces for wrapping components different from standard . Check usage examples in example/typescript-example.tsx.
NOTE library author is not using Typescript, so if you are using typings and found an issue, please submit a PR with fix. Thanks @iyegoroff for the initial TS support!
Development and testing
Currently is being developed and tested with the latest stable
Node on OSX.To run example covering all
DebounceInput features, use yarn start, which will compile example/Example.js`bash
git clone git@github.com:nkbt/react-debounce-input.git
cd react-debounce-input
yarn install
yarn startthen
open http://localhost:8080
`Tests
`bash
to run ESLint check
yarn lintto run tests
yarn test
``MIT