react性能优化之willunmount 销毁setTimeout,样式不要用行内式
文章目录
react组件对于一些异步任务的话,要及时清理,否则频繁渲染的话会造成异步任务持续增多,不会释放
解决方案
1、在componentWillUnmount时clearTimout() clearIntever()
2、在componentDidMount是clearTimout() clearIntever()之后再setTimeout() setIntever()
tips: promise无法清除掉
此外,style={{}}尽量不要使用,用className来代替
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论