侧边栏壁纸
博主头像
前端学习

行动起来,活在当下

  • 累计撰写 307 篇文章
  • 累计创建 18 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

react的生命周期(新旧版本)

Administrator
2022-05-24 / 0 评论 / 0 点赞 / 114 阅读 / 0 字

旧版本:

componentWillMount在渲染前调用,在客户端也在服务端。
componentDidMount在第一次渲染后调用,只在客户端。
componentWillReceiveProps 在组件接收到一个新的 prop (更新后)时被调用。这个方法在初始化render时不会被调用。
shouldComponentUpdate 返回一个布尔值。在组件接收到新的props或者state时被调用。在初始化时或者使用forceUpdate时不被调用。可以在你确认不需要更新组件时使用。
componentWillUpdate在组件接收到新的props或者state但还没有render时被调用。在初始化时不会被调用。
componentDidUpdate 在组件完成更新后立即调用。在初始化时不会被调用。
componentWillUnmount在组件从 DOM 中移除之前立刻被调用。
202110191634637104894238
202110191634637113134971
202110191634637121881786

新版本:

新版本中:

componentWillMount

componentWillReceiveProps

componentWillUpdate

必须加上UNSAFE_前缀,即:

UNSAFE_componentWillMount

UNSAFE_componentWillReceiveProps

UNSAFE_componentWillUpdate

0

评论区