Throttle the search term input

We have a function, where we pass some text data to serach menu, and we want to throttle it

<SearchBar onSearchTermChange={term => this.videoSearch(term)}/>

First of all we need to import lodash package

import _ from 'lodash'

Now we could debounce this function

const videoSearch = _.debounce((term) => {this.videoSearch(term)}, 300);

And replace it as attribute with variable-function

render() {
        const videoSearch = _.debounce((term) => {this.videoSearch(term)}, 300);
        return (
            <div>
                <SearchBar onSearchTermChange={videoSearch}/>
        ...

results matching ""

    No results matching ""