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 可以調(diào)整查看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

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容