ComponentDidCatch(用于实现错误边界)似乎在服务器端不起作用。 这是 React 当前的一个限制,有没有人找到解决这个问题的方法?
答案 0 :(得分:1)
import React from "react";
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError() {
return { hasError: true };
}
render() {
if (this.state.hasError) {
return "Internal Error.";
}
return this.props.children;
}
}