componentWillReceiveProps和componentDidUpdate区别

  参数 触发时机 更新方式
componentWillReceiveProps

componentWillReceiveProps(nextProps)

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

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

仅在props变化时会触发

更新状态是同步的,   

不触发重新render

componentDidUpdate

componentDidUpdate(preProps,preState,spanshot)

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

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

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

更新状态是异步的

触发重新render

 

 

componentWillReceiveProps即将废弃,推荐使用componentDidUpdate

posted @ 2020-03-26 14:45  全玉  阅读(7988)  评论(0编辑  收藏  举报