-
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.
- Loading branch information
Showing
7 changed files
with
115 additions
and
5 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
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,25 @@ | ||
import type { ReactNode } from 'react'; | ||
import { Suspense } from 'react'; | ||
import { ErrorBoundary } from 'react-error-boundary'; | ||
import { MoonLoader } from 'react-spinners'; | ||
|
||
import DefaultErrorFallback from './FetchErrorFallback'; | ||
|
||
interface FetchBoundaryProps { | ||
children: ReactNode; | ||
loadingFallback?: ReactNode; | ||
onReset?: () => void; | ||
} | ||
|
||
const FetchBoundary = ({ | ||
children, | ||
loadingFallback = <MoonLoader color="#7752FE" size={40} />, | ||
}: FetchBoundaryProps) => { | ||
return ( | ||
<ErrorBoundary FallbackComponent={DefaultErrorFallback}> | ||
<Suspense fallback={loadingFallback}>{children}</Suspense> | ||
</ErrorBoundary> | ||
); | ||
}; | ||
|
||
export default FetchBoundary; |
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,50 @@ | ||
import styled from '@emotion/styled'; | ||
import { useQueryErrorResetBoundary } from '@tanstack/react-query'; | ||
import type { FallbackProps } from 'react-error-boundary'; | ||
|
||
const FetchErrorFallback = ({ error, resetErrorBoundary }: FallbackProps) => { | ||
const { reset } = useQueryErrorResetBoundary(); | ||
|
||
const handleClickReset = () => { | ||
resetErrorBoundary(); | ||
reset(); | ||
}; | ||
|
||
return ( | ||
<ErrorContainer> | ||
<ErrorTitle>에러가 발생했습니다</ErrorTitle> | ||
<ErrorMessage>{error.message}</ErrorMessage> | ||
<RetryButton onClick={handleClickReset}>다시 시도</RetryButton> | ||
</ErrorContainer> | ||
); | ||
}; | ||
|
||
const ErrorContainer = styled.div` | ||
padding: 1rem; | ||
border-radius: 0.5rem; | ||
background-color: #fef2f2; | ||
color: #b91c1c; | ||
`; | ||
|
||
const ErrorTitle = styled.h2` | ||
font-size: 1.125rem; | ||
font-weight: 600; | ||
margin-bottom: 0.5rem; | ||
`; | ||
|
||
const ErrorMessage = styled.p` | ||
margin-bottom: 1rem; | ||
`; | ||
|
||
const RetryButton = styled.button` | ||
padding: 0.5rem 1rem; | ||
background-color: #dc2626; | ||
color: white; | ||
border-radius: 0.25rem; | ||
&:hover { | ||
background-color: #b91c1c; | ||
} | ||
`; | ||
|
||
export default FetchErrorFallback; |
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 |
---|---|---|
|
@@ -3963,6 +3963,13 @@ react-docgen@^7.0.0: | |
loose-envify "^1.1.0" | ||
scheduler "^0.23.2" | ||
|
||
react-error-boundary@^5.0.0: | ||
version "5.0.0" | ||
resolved "https://registry.yarnpkg.com/react-error-boundary/-/react-error-boundary-5.0.0.tgz#6b6c7e075c922afb0283147e5b084efa44e68570" | ||
integrity sha512-tnjAxG+IkpLephNcePNA7v6F/QpWLH8He65+DmedchDwg162JZqx4NmbXj0mlAYVVEd81OW7aFhmbsScYfiAFQ== | ||
dependencies: | ||
"@babel/runtime" "^7.12.5" | ||
|
||
react-hook-form@^7.53.2: | ||
version "7.53.2" | ||
resolved "https://registry.yarnpkg.com/react-hook-form/-/react-hook-form-7.53.2.tgz#6fa37ae27330af81089baadd7f322cc987b8e2ac" | ||
|
@@ -4008,6 +4015,11 @@ [email protected]: | |
dependencies: | ||
"@remix-run/router" "1.21.0" | ||
|
||
react-spinners@^0.15.0: | ||
version "0.15.0" | ||
resolved "https://registry.yarnpkg.com/react-spinners/-/react-spinners-0.15.0.tgz#bb9536a3839ab4e1513bb98847d79cc1fc930b93" | ||
integrity sha512-ZO3/fNB9Qc+kgpG3SfdlMnvTX6LtLmTnOogb3W6sXIaU/kZ1ydEViPfZ06kSOaEsor58C/tzXw2wROGQu3X2pA== | ||
|
||
"react@^16.8.0 || ^17.0.0 || ^18.0.0", react@^18.3.1: | ||
version "18.3.1" | ||
resolved "https://registry.yarnpkg.com/react/-/react-18.3.1.tgz#49ab892009c53933625bd16b2533fc754cab2891" | ||
|