Skip to content

Commit ec81d61

Browse files
authored
fix(useErrorHandler): use unknown instead of Error (#89)
* fix(useErrorHandler): use unknown instead of Error type * make the return type explicit * treat null and undefined as no error * docs(useErrorHandler): use unknown instead of error Closes #83
1 parent fb0b859 commit ec81d61

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ See the recovery examples above.
289289
This is called when the `resetKeys` are changed (triggering a reset of the
290290
`ErrorBoundary`). It's called with the `prevResetKeys` and the `resetKeys`.
291291

292-
### `useErrorHandler(error?: Error)`
292+
### `useErrorHandler(error?: unknown)`
293293

294294
React's error boundaries feature is limited in that the boundaries can only
295295
handle errors thrown during React's lifecycles. To quote

src/index.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,10 @@ function withErrorBoundary<P>(
165165
return Wrapped
166166
}
167167

168-
function useErrorHandler<P = Error>(
169-
givenError?: P | null | undefined,
170-
): React.Dispatch<React.SetStateAction<P | null>> {
171-
const [error, setError] = React.useState<P | null>(null)
172-
if (givenError) throw givenError
173-
if (error) throw error
168+
function useErrorHandler(givenError?: unknown): (error: unknown) => void {
169+
const [error, setError] = React.useState<unknown>(null)
170+
if (givenError != null) throw givenError
171+
if (error != null) throw error
174172
return setError
175173
}
176174

0 commit comments

Comments
 (0)