react基础知识总结

drug94501 12 0 pdf 2021-10-09 03:10:38

前言最近在准备面试。复习了一些react的知识点,特此总结。开始React 生命周期react 16以前的生命周期是这样的组件在首次渲染时会被实例化,然后调用实例上面的componentWillMount,render和componentDidMount函数。组件在更新渲染时可以调用componentWillReceiveProps,shouldComponentUpdate,componentWillUpdate,render和componentDidUpdate函数。借图:从 React v16.3 开始,React 建议使用getDerivedStateFromProps和getSnapshotBeforeUpdate两个生命周期函数替代 componentWillMount,componentWillReceiveProps和componentWillUpdate三个生命周期函数。这里需要注意的是 新增的两个生命周期 函数和原有的三个生命周期函数必须分开使用,不能混合使用目前的生命周期(借图):componentWillMount存在的问题有人认为在componentWillMount中可以提前进行异步请求,避免白屏。但是react在调用render渲染页面的时候,render并不会等待异步请求结束,再获取数据渲染。这么写是有潜在隐患的。而在react fiber之后 可能在一次渲染中多次调用。

react基础知识总结

react基础知识总结

react基础知识总结

react基础知识总结

react基础知识总结

用户评论
请输入评论内容
评分:
暂无评论