好程序员web前端培训分享React学习笔记(三)
好程序员web前端培训分享React学习笔记(三),组件的生命周期 React中组件也有生命周期,也就是说也有很多钩子函数供我们使用, 组件的生命周期,我们会分为四个阶段,初始化、运行中、销毁、错误处理(16.3之后) 初始化 在组件初始化阶段会执行 .constructor .static getDerivedStateFromProps() .componentWillMount() / UNSAFE_componentWillMount() .render() .componentDidMount() 更新阶段 props或state的改变可能会引起组件的更新,组件重新渲染的过程中会调用以下方法: .componentWillReceiveProps() / UNSAFE_componentWillReceiveProps() .static getDerivedStateFromProps() .shouldComponentUpdate() .componentWillUpdate() / UNSAFE_componentWillUpdate() .render() .getSnapshotBeforeUpdate() .componentDidUpdate() 卸载阶段 .componentWillUnmount() 错误处理