mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-11-22 19:08:36 +00:00
feat(web): wrap app in errorboundary
Prevents the app from failing on render errors as mentioned in #675. More to come..
This commit is contained in:
1 parent
4d7fee41bd
commit
aebef6d7de
2 files changed
+33
-6
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { Component, ReactNode, ErrorInfo } from 'react';
|
||||
|
||||
class ErrorBoundary extends Component<{ children: ReactNode }, { hasError: boolean }> {
|
||||
constructor(props: { children: ReactNode }) {
|
||||
super(props);
|
||||
this.state = { hasError: false };
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(err: Error) {
|
||||
return { hasError: true };
|
||||
}
|
||||
|
||||
componentDidCatch(error: Error, info: ErrorInfo) {
|
||||
console.error(error, info)
|
||||
this.setState({ hasError: false });
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.state.hasError ? null : this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
export default ErrorBoundary;
|
||||
Reference in new issue
Block a user