/
Example.js
59 lines (54 loc) · 1.06 KB
/
Example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Example
const x = React.createElement;
class ErrorBoundary extends React.Component {
static getDerivedStateFromError(error) {
return {
error: error,
};
}
componentDidCatch(error, errorInfo) {
console.log(error.message, errorInfo.componentStack);
this.setState({
componentStack: errorInfo.componentStack,
});
}
render() {
if (this.state && this.state.error) {
return x(
'div',
null,
x('h3', null, this.state.error.message),
x('pre', null, this.state.componentStack)
);
}
return this.props.children;
}
}
function Example() {
let state = React.useState(false);
return x(
ErrorBoundary,
null,
x(
DisplayName,
null,
x(
React.SuspenseList,
null,
x(
NativeClass,
null,
x(
BabelClass,
null,
x(
React.Suspense,
null,
x('div', null, x(Component, null, x(Throw)))
)
)
)
)
)
);
}