Gathering detailed insights and metrics for react-debounce-input
Gathering detailed insights and metrics for react-debounce-input
Gathering detailed insights and metrics for react-debounce-input
Gathering detailed insights and metrics for react-debounce-input
React component that renders Input with debounced onChange
npm install react-debounce-input
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
451 Stars
580 Commits
61 Forks
9 Watching
3 Branches
18 Contributors
Updated on 10 Oct 2024
Minified
Minified + Gzipped
JavaScript (94.32%)
TypeScript (4.59%)
CSS (1.09%)
Cumulative downloads
Total Downloads
Last day
-5.9%
73,898
Compared to previous day
Last week
0.4%
376,870
Compared to previous week
Last month
6.8%
1,664,352
Compared to previous month
Last year
27.4%
16,969,021
Compared to previous year
2
1
30
React component that renders an Input, Textarea or other element with debounced onChange. Can be used as drop-in replacement for <input type="text" />
or <textarea />
http://nkbt.github.io/react-debounce-input
http://codepen.io/nkbt/pen/VvmzLQ
1npm install --save react-debounce-input
1yarn add react-debounce-input
1<script src="https://unpkg.com/react@16.0.0/umd/react.production.min.js"></script> 2<script src="https://unpkg.com/react-debounce-input/build/react-debounce-input.js"></script> 3(Module exposed as `DebounceInput`)
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3import {DebounceInput} from 'react-debounce-input'; 4 5class App extends React.Component { 6 state = { 7 value: '' 8 }; 9 10 render() { 11 return ( 12 <div> 13 <DebounceInput 14 minLength={2} 15 debounceTimeout={300} 16 onChange={event => this.setState({value: event.target.value})} /> 17 18 <p>Value: {this.state.value}</p> 19 </div> 20 ); 21 } 22} 23 24const appRoot = document.createElement('div'); 25document.body.appendChild(appRoot); 26ReactDOM.render(<App />, appRoot);
element
: PropTypes.string or React.PropTypes.func (default: "input")You can specify element="textarea". For Example:
1<DebounceInput element="textarea" />
Will result in
1<textarea />
Note: when rendering a <textarea />
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 <input />
and <textarea />
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:
1<DebounceInput element={CustomReactComponent} />
Will result in
1<CustomReactComponent />
onChange
: PropTypes.func.isRequiredFunction called when value is changed (debounced) with original event passed through
value
: PropTypes.stringValue of the Input box. Can be omitted, so component works as usual non-controlled input.
minLength
: PropTypes.number (default: 0)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 ''
.
debounceTimeout
: PropTypes.number (default: 100)Notification debounce timeout in ms. If set to -1
, disables automatic notification completely. Notification will only happen by pressing Enter
then.
forceNotifyByEnter
: PropTypes.bool (default: true)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.
forceNotifyOnBlur
: PropTypes.bool (default: true)Same as forceNotifyByEnter
, but notification will be sent when focus leaves the input field.
inputRef
: PropTypes.func (default: undefined)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.
<input>
1<DebounceInput 2 type="number" 3 onChange={event => this.setState({value: event.target.value})} 4 placeholder="Name" 5 className="user-name" />
Will result in
1<input 2 type="number" 3 placeholder="Name" 4 className="user-name" />
This library has typescript typings, import them the same way as in javascript:
1import {DebounceInput} from 'react-debounce-input';
Also there are helper types DebounceTextArea
and Debounced
to provide strict interfaces for wrapping components different from standard <input />
. 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!
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
1git clone git@github.com:nkbt/react-debounce-input.git 2cd react-debounce-input 3yarn install 4yarn start 5 6# then 7open http://localhost:8080
1# to run ESLint check 2yarn lint 3 4# to run tests 5yarn test
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/13 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
38 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More