react手记(componentWillMount,componentDidMount等)
生命周期
componentWillMount 组件出现前 就是dom还没有渲染到html文档里面
componentDidMount 组件渲染完成 已经出现在dom文档里
可以再各个周期实现特定的操作
生命周期的方法有:
componentWillMount 在渲染前调用,在客户端也在服务端。
componentDidMount : 在第一次渲染后调用,只在客户端。之后组件已经生成了对应的DOM结构,可以通过this.getDOMNode()来进行访问。 如果你想和其他JavaScript框架一起使用,可以在这个方法中调用setTimeout, setInterval或者发送AJAX请求等操作(防止异部操作阻塞UI)。
componentWillReceiveProps 在组件接收到一个新的 prop (更新后)时被调用。这个方法在初始化render时不会被调用。
shouldComponentUpdate 返回一个布尔值。在组件接收到新的props或者state时被调用。在初始化时或者使用forceUpdate时不被调用。 可以在你确认不需要更新组件时使用。
componentWillUpdate在组件接收到新的props或者state但还没有render时被调用。在初始化时不会被调用。
componentDidUpdate 在组件完成更新后立即调用。在初始化时不会被调用。
componentWillUnmount在组件从 DOM 中移除的时候立刻被调用。
React 组件生命周期:http://www.runoob.com/react/react-component-life-cycle.html
React.Component:https://reactjs.org/docs/react-component.html#lifecycle-methods
构成与继承:https://reactjs.org/docs/composition-vs-inheritance.html
React组件生命周期过程说明:http://react-china.org/t/react/1740
相关文章
- React-Context
- [转] 使用babel-plugin-react-css-modules简化CSS Modules的使用
- [转] React Router 使用教程
- 实现 react 中的状态保存
- react-router
- React Native商城项目实战01 - 初始化设置
- React常用方法手记
- 从零开始的react入门教程(八),redux起源与基础用法
- React 中的函数式思想
- React和Vue组件间数据传递demo
- react页面跳转 window.location.href和window.open的几种用法和区别
- react-native-router-flux 定义底部导航栏 定义菜单图标及文字
- react-redux中@connect
- React Native项目实战之fetch请求
- react hooks沉思录
- React-Native学习指南
- React-Native学习指南
- React动画库之react-transition-group(入场enter、出场exit、初始化appear)
- React实践:Vite创建React项目、react事件传递参数的两种方式
- React-hooks的useEffect模拟componentDidUpdate生命周期