-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: QueryErrorBoundary 컴포넌트 작성 (#163)
* chore: 전역 쿼리 기본 옵션 설정 * feat: QueryErrorBoundary 기능 작성 * feat: QueryErrorBoundary 화면 작성 * refactor: fallback UI 분리 * rename: 디렉토리 이름 ErrorBoundary 로 변경 * feat: UnknownFallback 작성 * style: QueryErrorBoundary JSDOC 주석 추가 * feat: 전역 ErrorBoundary 설정 * fix: 빌드 오류 해결
- Loading branch information
1 parent
e4224aa
commit 862f5c9
Showing
9 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,26 @@ | ||
import { useErrorBoundaryFallbackProps } from '@suspensive/react'; | ||
|
||
const NetworkFallback = () => { | ||
const { reset } = useErrorBoundaryFallbackProps(); | ||
|
||
return ( | ||
<div className="flex h-full w-full flex-col items-center justify-center"> | ||
<img | ||
src="/assets/PageError.png" | ||
alt="오류" | ||
/> | ||
<h1 className="mt-5 text-3xl font-bold">오류 발생</h1> | ||
<p className="text-lg leading-10 text-dark-gray"> | ||
정보를 불러올 수 없어요. | ||
</p> | ||
<button | ||
className="btn btn-light-point dark:btn-dark-point mt-5 flex w-32 items-center justify-center rounded-lg" | ||
onClick={reset} | ||
> | ||
다시 불러오기 | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NetworkFallback; |
33 changes: 33 additions & 0 deletions
33
src/shared/ErrorBoundary/components/QueryErrorBoundary.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,33 @@ | ||
import { FunctionComponent, ReactNode, PropsWithChildren } from 'react'; | ||
import { ErrorBoundary, ErrorBoundaryFallbackProps } from '@suspensive/react'; | ||
import { useQueryErrorResetBoundary } from '@tanstack/react-query'; | ||
|
||
interface QueryErrorBoundaryProps { | ||
fallback: | ||
| FunctionComponent<ErrorBoundaryFallbackProps<Error>> | ||
| NonNullable<ReactNode>; | ||
} | ||
|
||
/** | ||
* QueryErrorBoundary를 래핑한 ErrorBoundary 컴포넌트입니다. | ||
* 쿼리 에러가 발생했을 때, 쿼리를 리셋하는 함수를 담고 fallback을 렌더링합니다. | ||
* @param fallback - 오류 발생 시 렌더링할 컴포넌트. | ||
* @param children - 성공 시 렌더링할 컴포넌트. | ||
*/ | ||
const QueryErrorBoundary = ({ | ||
fallback, | ||
children | ||
}: PropsWithChildren<QueryErrorBoundaryProps>) => { | ||
const { reset } = useQueryErrorResetBoundary(); | ||
|
||
return ( | ||
<ErrorBoundary | ||
onReset={reset} | ||
fallback={fallback} | ||
> | ||
{children} | ||
</ErrorBoundary> | ||
); | ||
}; | ||
|
||
export default QueryErrorBoundary; |
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,24 @@ | ||
import { Link } from 'react-router-dom'; | ||
|
||
const UnknownFallback = () => { | ||
return ( | ||
<div className="flex h-full w-full flex-col items-center justify-center"> | ||
<img | ||
src="/assets/UnknownError.png" | ||
alt="오류" | ||
/> | ||
<h1 className="mt-5 text-3xl font-bold">오류 발생</h1> | ||
<p className="text-lg leading-10 text-dark-gray"> | ||
내부적인 문제로 오류가 발생했어요. | ||
</p> | ||
<Link | ||
className="btn btn-light-point dark:btn-dark-point mt-5 flex w-32 items-center justify-center rounded-lg" | ||
to={'/'} | ||
> | ||
홈으로 | ||
</Link> | ||
</div> | ||
); | ||
}; | ||
|
||
export default UnknownFallback; |
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,3 @@ | ||
export { default as QueryErrorBoundary } from './components/QueryErrorBoundary'; | ||
export { default as NetworkFallback } from './components/NetworkFallback'; | ||
export { default as UnknownFallback } from './components/UnknownFallback'; |