// 后面用泛型来规范类型标签:jira,用泛,15,value,setDebouncedValue,delay,const,useEffect From: https://blog.51cto.com/u_15460007/6052219
export const useDebounce = <V>(value: V, delay?: number) => {
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(() => {
// 每次在value变化以后,设置一个定时器
const timeout = setTimeout(() => setDebouncedValue(value), delay);
// 每次在上一个useEffect处理完以后再运行
return () => clearTimeout(timeout);
}, [value, delay]);
return debouncedValue;
};