javascript - lodash.debounce search in react js -


i'm trying debounce search in react using lodash, debounce.

but when ever run i'm receiving type error

typeerror: cannot read property 'debounce' of undefined

i have tried moving around in code can't understand why isn't working

i started off importing

import { _, debounce } 'lodash'

i have input following

<input     type="text"     value={this.state.query}     onchange={(e) => {this.updatequery(e.target.value)}}     placeholder="search title or author" /> 

connected function

updatequery = (query) => {     _.debounce(() => query(this.setstate({ query }), 500))     this.onbooksearch(query) } 

does understand why is?

i think import problem. want import _ default:

import _, {debounce} 'lodash'; 

also you're not using extracted function:

updatequery = (query) => {   debounce(() => query(this.setstate({ query }), 500))   this.onbooksearch(query) } 

since you're extracting {debounce} in import can use directly.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -