Skip to content
Snippets Groups Projects
Commit d0dc7a65 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[dome/errors] upgrade to new React API

parent c8670e77
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
*/ */
import React, { ReactNode } from 'react'; import React, { ReactNode } from 'react';
import { Debug } from 'dome'; import { DEVEL, Debug } from 'dome';
import { Label } from 'dome/controls/labels'; import { Label } from 'dome/controls/labels';
import { Button } from 'dome/controls/buttons'; import { Button } from 'dome/controls/buttons';
...@@ -53,7 +53,6 @@ export interface CatchProps { ...@@ -53,7 +53,6 @@ export interface CatchProps {
label?: string; label?: string;
/** Alternative renderer callback in case of errors. */ /** Alternative renderer callback in case of errors. */
onError?: JSX.Element | ErrorRenderer; onError?: JSX.Element | ErrorRenderer;
children: ReactNode; children: ReactNode;
} }
...@@ -62,25 +61,34 @@ interface CatchState { ...@@ -62,25 +61,34 @@ interface CatchState {
info?: unknown; info?: unknown;
} }
/* eslint-disable react/prop-types */
/** /**
React Error Boundaries. React Error Boundaries.
*/ */
export class Catch extends React.Component<CatchProps, CatchState, unknown> { export class Catch extends React.Component<CatchProps, CatchState, unknown> {
constructor(private p: CatchProps) { constructor(props: CatchProps) {
super(p); super(props);
this.state = {}; this.state = {};
this.logerr = this.logerr.bind(this); this.logerr = this.logerr.bind(this);
this.reload = this.reload.bind(this); this.reload = this.reload.bind(this);
} }
componentDidCatch(error: unknown, info: unknown): void { componentDidCatch(error: unknown, info: unknown): void {
this.setState({ error, info }); if (DEVEL) {
const { label='Error' } = this.props;
D.error(label, ': ', error, info);
}
}
static getDerivedStateFromError(error: unknown, info: unknown): CatchState {
return { error, info };
} }
logerr(): void { logerr(): void {
const { error, info } = this.state; const { error, info } = this.state;
D.error('catched error:', error, info); D.error('Catched error:', error, info);
} }
reload(): void { reload(): void {
...@@ -89,7 +97,7 @@ export class Catch extends React.Component<CatchProps, CatchState, unknown> { ...@@ -89,7 +97,7 @@ export class Catch extends React.Component<CatchProps, CatchState, unknown> {
render(): JSX.Element { render(): JSX.Element {
const { error, info } = this.state; const { error, info } = this.state;
const { onError, label = 'Error' } = this.p; const { onError, label = 'Error' } = this.props;
if (error) { if (error) {
if (typeof onError === 'function') if (typeof onError === 'function')
return onError(error, info, this.reload); return onError(error, info, this.reload);
...@@ -106,7 +114,7 @@ export class Catch extends React.Component<CatchProps, CatchState, unknown> { ...@@ -106,7 +114,7 @@ export class Catch extends React.Component<CatchProps, CatchState, unknown> {
</div> </div>
); );
} }
return (<>{this.p.children}</>); return (<>{this.props.children}</>);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment