Debugging React App

Debugging React App

  • Understanding error message
  • Finding Logical Errors by using Dev Tools & Source maps
浏览器source map工具

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

  • React develper tools in chrome store
React Developer Tools

=>components 可以调整查看props state

  • Error boundaries (react 16+)
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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。