mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-11 10:53:45 +01:00
30 lines
No EOL
637 B
JavaScript
30 lines
No EOL
637 B
JavaScript
import React from 'react';
|
|
|
|
export default function errorBoundary(message, fix) {
|
|
return function(Comp) {
|
|
return class extends React.Component {
|
|
|
|
state = {
|
|
hasError: false,
|
|
fixAttempt: false
|
|
};
|
|
|
|
componentDidCatch() {
|
|
this.setState({hasError: true});
|
|
if (!this.state.fixAttempt) {
|
|
if (fix) {
|
|
fix(this.props);
|
|
this.setState({hasError: false, fixAttempt: true});
|
|
}
|
|
}
|
|
}
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
return message || null;
|
|
}
|
|
return <Comp {...this.props} />;
|
|
}
|
|
}
|
|
}
|
|
} |