Debugging React App

2020-05-23  本文已影响0人  33jubi

Debugging React App

浏览器source map工具

Source=>指定文件=》指定某行=》跑=》用工具看上一步下一步各值的变化

React Developer Tools

=>components 可以调整查看props state

Error boundaries (react 16+)

only use when u know it may be fail and u can control it
=>to show customer ur cutomer error message
Error boundary.js

import React,{Component} from 'react'
export default class ErrorBoundary extends Component{
  state={
    hasError:false;
    errorMessage:''
  }
  componentDidCatch = (error,info)=>{
    this.setState({hasError:true,errorMessage:error});
  }
  render(){
    if(this.state.hasError){
      return <h1>{this.state.errorMessage}</h1>
    }else{
      return this.props.children
    }
  }
}


....
<ErrorBoundary>
  <Person/>
</ErrorBoundary>

Useful Resources & Links

上一篇下一篇

猜你喜欢

热点阅读