React16 新特性

  1. 多了一个错误组件Error Boundaries,需要加上生命周期
  • componentDidCatch 用来记录错误信息
  • static getDerivedStateFromError 用来返回一个state。渲染UI
  1. render可以返回数组类型, 不需要外面加一层div了, 也可以用React.Fragments组件
  2. 自定义的dom属性不会被react截掉了
  3. createProtal 可以指定放在哪个dom节点下面, 但是不影响react的虚拟dom结构。dom结构可以好一些(比如全局弹窗)
  4. 渲染机制改变了, 不过目前默认还是以前的渲染机制, 需要手动打开. 会影响到生命周期执行多次的问题
  5. 更新了获取ref的方式. 是用React.createRef()
  6. 更新了使用context的方式. React.createContext(), 子组件就算shouldComponentUpdate返回值是false, 照样会更新.
  • constructor(props, context)
  • componentWillReceiveProps(nextProps, nextContext)
  • shouldComponentUpdate(nextProps, nextState, nextContext)
  • componetWillUpdate(nextProps, nextState, nextContext)
  • Consumer

你可能感兴趣的:(React16 新特性)