Skip to content

Commit

Permalink
fix(react): update BaseErrorBoundary method simply (#154)
Browse files Browse the repository at this point in the history
* fix(react): update BaseErrorBoundary method simply

* Create gentle-laws-reflect.md
  • Loading branch information
manudeli authored Sep 18, 2023
1 parent d636e85 commit 482cfc4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-laws-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@suspensive/react": patch
---

fix(react): update BaseErrorBoundary method simply
12 changes: 4 additions & 8 deletions packages/react/src/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,16 @@ 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()
}
}

componentDidCatch(error: Error, info: ErrorInfo) {
this.props.onError?.(error, info)
}

resetErrorBoundary = () => {
this.props.onReset?.()
this.reset()
}

reset() {
this.props.onReset?.()
awaitClient.clearError()
this.setState(initialState)
}
Expand All @@ -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
Expand All @@ -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} />
Expand Down

1 comment on commit 482cfc4

@vercel
Copy link

@vercel vercel bot commented on 482cfc4 Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visualization – ./websites/visualization

visualization-git-main-suspensive.vercel.app
visualization.suspensive.org
visualization-suspensive.vercel.app

Please sign in to comment.