Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function debounce (fn, time) {
- let timeoutId
- return wrapper
- function wrapper (...args) {
- if (timeoutId) {
- clearTimeout(timeoutId)
- }
- timeoutId = setTimeout(() => {
- timeoutId = null
- fn(...args)
- }, time)
- }
- }
- class SearchMedicine extends React.Component {
- constructor (props) {
- super(props)
- this.searchMedicineOnChange = this.searchMedicineOnChange.bind(this)
- }
- searchMedicineOnChange = debounce(value => {
- if (value.length > 3) {
- this.props.searchMedicineLoading(
- this.props.searchMedicineState,
- this.props.checkPincodeState.payload.id,
- value
- )
- }
- }, 1000)
- render() {
- return (
- <input onChange={this.searchMedicineOnChange} />
- )
- }
Add Comment
Please, Sign In to add comment