Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

debounce react

//debounce with react js
// import useState hook
const [productName, setProductName] = useState("");
//write debounce function 
let timeOutId;
const handleSearch = (value)=>{
      if(timeOutId){clearTimeout(timeOutId)}
     timeOutId =  setTimeout(() => {setProductName(value)},500)
  }
//ui 
 <input type="text" onChange={(e) => handleSearch(e.target.value)} />
 
PREVIOUS NEXT
Tagged: #debounce #react
ADD COMMENT
Topic
Name
7+1 =