diff --git a/scm-ui-components/packages/ui-components/src/errorboundary/PageErrorBoundary.js b/scm-ui-components/packages/ui-components/src/errorboundary/PageErrorBoundary.js new file mode 100644 index 0000000000..2be112455e --- /dev/null +++ b/scm-ui-components/packages/ui-components/src/errorboundary/PageErrorBoundary.js @@ -0,0 +1,32 @@ +//@flow + +import * as React from "react"; + + +class PageErrorBoundary extends React.Component { + constructor(props) { + super(props); + this.state = { hasError: false }; + } + + /** + * This lifecycle is invoked after an error has been thrown by a descendant component. + * It receives the error that was thrown as a parameter and should return a value to update state. + * @param error + * @returns {{hasError: boolean}} + */ + static getDerivedStateFromError(error) { + // Update state so the next render will show the fallback UI. + return { hasError: true }; + } + + render() { + if (this.state.hasError) { + return