useEffect react 下一次调用到达时如何取消超时
how to cancel timeout when next calling arrives in useEffect react
我想在下次来电时清除或取消超时。
React.useEffect(() => {
// set timeout to control unwanted searches
setTimeout(doSearch, 300);
return () => {
// prevent search to call if new Search request arrives ?
};
}, [searchKey]);
以这种方式清除您之前的计时器
React.useEffect(() => {
const timer = setTimeout(doSearch, 300);
return () => {
clearTimeout(timer)
};
}, [searchKey]);
我想在下次来电时清除或取消超时。
React.useEffect(() => {
// set timeout to control unwanted searches
setTimeout(doSearch, 300);
return () => {
// prevent search to call if new Search request arrives ?
};
}, [searchKey]);
以这种方式清除您之前的计时器
React.useEffect(() => {
const timer = setTimeout(doSearch, 300);
return () => {
clearTimeout(timer)
};
}, [searchKey]);