How to start search only when user stops typing?

后端 未结 10 1789

I need to perform a Search when user stops typing.I know I am supposed to use setTimeout() . But with Reactjs I cant find how it works. Can

10条回答
  •  旧巷少年郎
    2020-12-07 19:02

    I used the debounce function of lodash

    onChangeSearchInput = (evt)=> {
        this.debouncedSearch(evt.target.value);
    };
    
    debouncedSearch = debounce(function (query) {
        this.setState({query});
    }, 1000);
    

    Somewhere in my render method i have this input field

    
    

提交回复
热议问题