From 482cfc45ae0e5e0c0874e87b6ea6a7a18081981a Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko <manudeli.ko@gmail.com> Date: Tue, 19 Sep 2023 00:22:05 +0900 Subject: [PATCH] fix(react): update BaseErrorBoundary method simply (#154) * fix(react): update BaseErrorBoundary method simply * Create gentle-laws-reflect.md --- .changeset/gentle-laws-reflect.md | 5 +++++ packages/react/src/ErrorBoundary.tsx | 12 ++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 .changeset/gentle-laws-reflect.md diff --git a/.changeset/gentle-laws-reflect.md b/.changeset/gentle-laws-reflect.md new file mode 100644 index 000000000..e1c810361 --- /dev/null +++ b/.changeset/gentle-laws-reflect.md @@ -0,0 +1,5 @@ +--- +"@suspensive/react": patch +--- + +fix(react): update BaseErrorBoundary method simply diff --git a/packages/react/src/ErrorBoundary.tsx b/packages/react/src/ErrorBoundary.tsx index 06e0ebc96..087d9058a 100644 --- a/packages/react/src/ErrorBoundary.tsx +++ b/packages/react/src/ErrorBoundary.tsx @@ -73,7 +73,7 @@ class BaseErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState const { isError } = this.state const { resetKeys } = this.props if (isError && prevState.isError && hasResetKeysChanged(prevProps.resetKeys, resetKeys)) { - this.resetErrorBoundary() + this.reset() } } @@ -81,12 +81,8 @@ class BaseErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState this.props.onError?.(error, info) } - resetErrorBoundary = () => { - this.props.onReset?.() - this.reset() - } - reset() { + this.props.onReset?.() awaitClient.clearError() this.setState(initialState) } @@ -99,7 +95,7 @@ class BaseErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState if (typeof fallback === 'function') { return createElement(fallback, { error, - reset: this.resetErrorBoundary, + reset: this.reset, }) } return fallback @@ -119,7 +115,7 @@ export const ErrorBoundary = forwardRef<{ reset(): void }, ErrorBoundaryProps>(( const ref = useRef<BaseErrorBoundary>(null) useImperativeHandle(resetRef, () => ({ - reset: () => ref.current?.resetErrorBoundary(), + reset: () => ref.current?.reset(), })) return <BaseErrorBoundary {...props} resetKeys={resetKeys} ref={ref} />