美文网首页
Debugging React App

Debugging React App

作者: 33jubi | 来源:发表于2020-05-23 15:16 被阅读0次

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

相关文章

网友评论

      本文标题:Debugging React App

      本文链接:https://www.haomeiwen.com/subject/fxxlahtx.html