insomnia/app/ui/components/base/DebouncedInput.js

32 lines
764 B
JavaScript
Raw Normal View History

2016-11-10 21:03:12 +00:00
import React, {Component, PropTypes} from 'react';
import {debounce} from '../../../common/misc';
2016-11-10 21:03:12 +00:00
class DebouncedInput extends Component {
_handleValueChange = debounce(this.props.onChange, 500);
_handleChange = e => this._handleValueChange(e.target.value);
2016-11-10 21:03:12 +00:00
render () {
// NOTE: Strip out onChange because we're overriding it
const {onChange, textarea, ...props} = this.props;
if (textarea) {
return (
<textarea {...props} onChange={this._handleChange}/>
)
} else {
return (
<input {...props} onChange={this._handleChange}/>
)
}
2016-11-10 21:03:12 +00:00
}
}
DebouncedInput.propTypes = {
// Required
2016-11-10 21:03:12 +00:00
onChange: PropTypes.func.isRequired,
// Optional
textarea: PropTypes.bool,
2016-11-10 21:03:12 +00:00
};
export default DebouncedInput;