-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): merge catchOn, throwOn as enabled (#570)
# Overview I merge `catchOn`, `throwOn` as `enabled` to simplify them. Specially thanks to @tooooo1, @sungh0lim, you make me make them as one ### Why name it as `enabled` 1. Positive word that mean condition 2. Friendly word (React Suspense user have used `enabled` option of TanStack Query's useQuery before mostly) 3. It can make meaning ErrorBoundary catch all error in children as default. others can not ## AS-IS (`catchOn`, `throwOn`)  ## TO-BE (`enabled`)  ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
- Loading branch information
Showing
8 changed files
with
108 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
"@suspensive/react": minor | ||
'@suspensive/react': minor | ||
--- | ||
|
||
feat(react): add catchOn throwOn prop on ErrorBoundary | ||
feat(react): add enabled prop of ErrorBoundary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type ConstructorType<TClass> = new (...args: any[]) => TClass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export type { PropsWithDevMode } from './PropsWithDevMode' | ||
export type { OmitKeyOf } from './OmitKeyOf' | ||
export type { ConstructorType } from './ConstructorType' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
websites/visualization/src/app/react/ErrorBoundary/catchOn/page.tsx
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
websites/visualization/src/app/react/ErrorBoundary/enabled/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use client' | ||
|
||
import { ErrorBoundary, Suspense } from '@suspensive/react' | ||
import { useSuspenseQuery } from '@suspensive/react-query' | ||
import { useQueryErrorResetBoundary } from '@tanstack/react-query' | ||
import { AxiosError, isAxiosError } from 'axios' | ||
import { Area, Box, Button } from '~/components/uis' | ||
import { api } from '~/utils' | ||
|
||
export default function Page() { | ||
const queryError = useQueryErrorResetBoundary() | ||
|
||
return ( | ||
<ErrorBoundary | ||
onReset={queryError.reset} | ||
fallback={({ error, reset }) => ( | ||
<Box.Error> | ||
Global: unknown error: {error.message} | ||
<Button onClick={reset}>↻</Button> | ||
</Box.Error> | ||
)} | ||
> | ||
<Area title="Page" className="h-96"> | ||
<ErrorBoundary | ||
enabled={AxiosError} // enabled only AxiosError | ||
onReset={queryError.reset} | ||
fallback={({ error, reset }) => ( | ||
<Box.Error> | ||
Page: AxiosError: Network error: {error.message} | ||
<Button onClick={reset}>↻</Button> | ||
</Box.Error> | ||
)} | ||
> | ||
<Area title="Section"> | ||
<ErrorBoundary | ||
enabled={(error) => !isAxiosError(error)} // enabled if not AxiosError | ||
onReset={queryError.reset} | ||
fallback={({ error, reset }) => ( | ||
<Box.Error> | ||
Section: {error.message} | ||
<Button onClick={reset}>↻</Button> | ||
</Box.Error> | ||
)} | ||
> | ||
<Suspense clientOnly> | ||
<AxiosErrorOrJustErrorMaker /> | ||
</Suspense> | ||
</ErrorBoundary> | ||
</Area> | ||
</ErrorBoundary> | ||
</Area> | ||
</ErrorBoundary> | ||
) | ||
} | ||
|
||
const AxiosErrorOrJustErrorMaker = () => { | ||
if (Math.random() > 0.5) { | ||
throw new Error('sometimes not AxiosError') | ||
} | ||
|
||
useSuspenseQuery({ | ||
queryKey: ['ErrorBoundary', 'enabled'], | ||
queryFn: () => api.delay(1000, { percentage: 0 }), | ||
}) | ||
|
||
return <>success</> | ||
} |
76 changes: 0 additions & 76 deletions
76
websites/visualization/src/app/react/ErrorBoundary/throwOn/page.tsx
This file was deleted.
Oops, something went wrong.