Answers for "react search when stop typing"

0

react search when stop typing

const [inputValue, setInputValue] = useState('');
const [typingTimeout, setTypingTimeout] = useState(0);

const doSearch = () => {
  // search
};

const handleInputChange = e => {
  if (typingTimeout) {
    clearTimeout(typingTimeout);
  }
  setInputValue(e.target.value);
  // Start searching after 0.5 seconds
  setTypingTimeout(setTimeout(doSearch, 500));
}

return (
  <input value={inputValue} onChange={handleInputChange} />
);
Posted by: Guest on February-05-2021

Code answers related to "react search when stop typing"

Code answers related to "Javascript"

Browse Popular Code Answers by Language