当前位置:服务支持 >  软件文章 >  学习笔记Jira项目10:优化策略:useDebounce解决请求过快问题

学习笔记Jira项目10:优化策略:useDebounce解决请求过快问题

阅读数 482
点赞 64
article_banner


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;
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
相关文章
QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利