1. React v16.0的生命周期函数有哪些?
componentWillMountrendercomponentDidMountcomponentWillRecivePropsshouldComponentUpdatecomponentWillUpdaterendercomponentDidUpdatecomponentWillUnmount
2. React v16.8前函数组件与类组件的区别是什么?
- 函数组件
- 语法上:纯函数
- 状态管理:无状态组件、不可使用
state、setState、生命周期函数
- 类组件
- 语法上:继承
React.Component并且创建render函数 - 状态管理:可使用
state、setState、生命周期函数
- 语法上:继承
3. React合成事件与DOM原生事件的区别是什么?
- React合成事件
- 驼峰
- 事件委托至
document节点
- DOM原生事件
- 小写
- 事件绑定在
DOM节点上
4. setState是异步还是同步的?
-
进入了React的调度流程,则为异步
-
未进入React的调度流程,则为同步,如
setTimeout、setInterval、直接在DOM上绑定原生事件