W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
React 16之前的版本,僅需接入插件即可,無(wú)需額外配置。
對(duì)于React 16及其以后的版本,需要在src/index.js中進(jìn)行額外配置:
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
componentDidCatch(error, info) {
this.setState({ hasError: true });
// 將component中的報(bào)錯(cuò)發(fā)送到Fundebug
fundebug.notifyError(error, {
metaData: {
info: info
}
});
}
render() {
if (this.state.hasError) {
return null
// 也可以在出錯(cuò)的component處展示出錯(cuò)信息
// return <h1>出錯(cuò)了!</h1>;
}
return this.props.children;
}
}
ReactDOM.render( < ErrorBoundary > < App / > < /ErrorBoundary>, document.getElementById('root'));
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: