完整错误边界方法
填空题 中等
题目
Fill in 空白使用方法那个更新状态 on 错误.
代码
class ErrorBoundary extends React.Component {
static _____(error) {
return { hasError: true };
}
render() {
if (this.state.hasError) return <h1>Error!</h1>;
return this.props.children;
}
}
提示
这个静态方法是 called 当错误是 thrown 期间渲染.
解释
getDerivedStateFromError 是静态 lifecycle 方法 called 当 descendant throws 错误. 它接收错误 and 返回状态更新到 show fallback UI.
相关资源
相关课程
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。