首页 > 其他 > 详细

componentWillReceiveProps和componentDidUpdate区别

时间:2020-03-26 15:17:27      阅读:214      评论:0      收藏:0      [点我收藏+]
  参数 触发时机 更新方式
componentWillReceiveProps

componentWillReceiveProps(nextProps)

只有一个参数nextProps,下一次的props

收到新的props之前做一些事情

仅在props变化时会触发

更新状态是同步的,   

不触发重新render

componentDidUpdate

componentDidUpdate(preProps,preState,spanshot)

有三个参数,上一次的props,上一次的state,和快照

收到新的props或新的state之后做一些事情

props和state变化都会触发,所有在此更新状态一定要有判断条件

更新状态是异步的

触发重新render

 

 

componentWillReceiveProps即将废弃,推荐使用componentDidUpdate

componentWillReceiveProps和componentDidUpdate区别

原文:https://www.cnblogs.com/mengff/p/12574405.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!