Skip to content

Commit

Permalink
🎉 각 리스트 컴포넌트 에러바운더리 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
doggopawer committed Nov 29, 2023
1 parent 2aeb19f commit b95eafc
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 32 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"next-themes": "^0.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.11",
"react-hook-form": "^7.47.0",
"react-lottie-player": "^1.5.5",
"sharp": "^0.32.6",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { useEffect, useRef } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import { useSearchParams } from 'next/navigation'
import ExceptionBoundary from '@/components/domain/exception-boundary'
import { useCardsQuery } from '@/hooks/api/queries/useCardsQuery'
Expand Down Expand Up @@ -54,7 +55,9 @@ const CardListContent = () => {
isEmpty={isEmpty}
isFetchingNextPage={isFetchingNextPage}
>
<CardList />
<ErrorBoundary fallback={<div>렌더링 중 문제가 발생했습니다.</div>}>
<CardList />
</ErrorBoundary>
</ExceptionBoundary>
<div ref={lastElementRef} />
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { useEffect, useRef, useState } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import ExceptionBoundary from '@/components/domain/exception-boundary'
import { useMyCardsQuery } from '@/hooks/api/queries/useMyCardsQuery'
import { useIntersectionObserver } from '@/hooks/useIntersectionObserver'
Expand Down Expand Up @@ -48,7 +49,9 @@ const MyCardListContent = () => {
isEmpty={isEmpty}
isFetchingNextPage={isFetchingNextPage}
>
<MyCardList data={data} />
<ErrorBoundary fallback={<div>렌더링 중 문제가 발생했습니다.</div>}>
<MyCardList data={data} />
</ErrorBoundary>
</ExceptionBoundary>

<div ref={lastElementRef} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ const MyCardList = ({
data,
}: {
data: InfiniteData<GetMyCardListRes, unknown> | undefined
}) => (
<>
{data?.pages.map(({ data: { cardList } }: GetMyCardListRes, pageIndex) => (
<Fragment key={pageIndex}>
{cardList.map((myCard: Card) => (
<MyCard key={myCard.cardId} card={myCard} />
))}
</Fragment>
))}
</>
)
}) => {
return (
<>
{data?.pages.map(
({ data: { cardList } }: GetMyCardListRes, pageIndex) => (
<Fragment key={pageIndex}>
{cardList.map((myCard: Card) => (
<MyCard key={myCard.cardId} card={myCard} />
))}
</Fragment>
),
)}
</>
)
}

export default MyCardList
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { useEffect, useRef, Fragment } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import ExceptionBoundary from '@/components/domain/exception-boundary'
import { useChatRoomsQuery } from '@/hooks/api/queries/useChatRoomsQuery'
import { useIntersectionObserver } from '@/hooks/useIntersectionObserver'
Expand Down Expand Up @@ -39,7 +40,9 @@ const ChatRoomListContent = () => {
isEmpty={isEmpty}
isFetchingNextPage={isFetchingNextPage}
>
<ChatRoomList data={data} />
<ErrorBoundary fallback={<div>렌더링 중 문제가 발생했습니다.</div>}>
<ChatRoomList data={data} />
</ErrorBoundary>
</ExceptionBoundary>

<div ref={lastElementRef} />
Expand Down
5 changes: 4 additions & 1 deletion src/app/(root)/(routes)/dibs/components/MyDibsTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { useEffect, useRef } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import ExceptionBoundary from '@/components/domain/exception-boundary'
import { useMyDibsQuery } from '@/hooks/api/queries/useMyDibsQuery'
import { useIntersectionObserver } from '@/hooks/useIntersectionObserver'
Expand Down Expand Up @@ -40,7 +41,9 @@ const MyDibsTemplate = () => {
isEmpty={isEmpty}
isFetchingNextPage={isFetchingNextPage}
>
<MyDibsList data={data} />
<ErrorBoundary fallback={<div>렌더링 중 문제가 발생했습니다.</div>}>
<MyDibsList data={data} />
</ErrorBoundary>
</ExceptionBoundary>

<div ref={lastElementRef} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { useEffect, useRef, Fragment } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import ExceptionBoundary from '@/components/domain/exception-boundary'
import { useMyTradeHistoryQuery } from '@/hooks/api/queries/useMyTradeHistoriesQuery'
import { useIntersectionObserver } from '@/hooks/useIntersectionObserver'
Expand Down Expand Up @@ -39,7 +40,9 @@ const MyTradeHistoryListContent = () => {
isEmpty={isEmpty}
isFetchingNextPage={isFetchingNextPage}
>
<MyTradeHistoryList data={data} />
<ErrorBoundary fallback={<div>렌더링 중 문제가 발생했습니다.</div>}>
<MyTradeHistoryList data={data} />
</ErrorBoundary>
</ExceptionBoundary>

<div ref={lastElementRef} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { useEffect, useRef, useState } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import ExceptionBoundary from '@/components/domain/exception-boundary'
import { useNotificationsQuery } from '@/hooks/api/queries/useNotificationsQuery'
import { useIntersectionObserver } from '@/hooks/useIntersectionObserver'
Expand Down Expand Up @@ -45,7 +46,9 @@ const NotificationListContent = () => {
isEmpty={isEmpty}
isFetchingNextPage={isFetchingNextPage}
>
<NotificationList data={data} />
<ErrorBoundary fallback={<div>렌더링 중 문제가 발생했습니다.</div>}>
<NotificationList data={data} />
</ErrorBoundary>
</ExceptionBoundary>
<div ref={lastElementRef} />
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { useEffect, useRef, useState } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import { useParams } from 'next/navigation'
import ExceptionBoundary from '@/components/domain/exception-boundary'
import { useMySuggestionsQuery } from '@/hooks/api/queries/useMySuggestionsQuery'
Expand Down Expand Up @@ -51,11 +52,13 @@ const MySuggestionListContent = () => {
isEmpty={isEmpty}
isFetchingNextPage={isFetchingNextPage}
>
<MySuggestionList
data={data}
suggestionTypeState={suggestionTypeState}
directionTypeState={directionTypeState}
/>
<ErrorBoundary fallback={<div>렌더링 중 문제가 발생했습니다.</div>}>
<MySuggestionList
data={data}
suggestionTypeState={suggestionTypeState}
directionTypeState={directionTypeState}
/>
</ErrorBoundary>
</ExceptionBoundary>

<div ref={lastElementRef} />
Expand Down
13 changes: 3 additions & 10 deletions src/components/domain/exception-boundary/ExceptionBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,20 @@ const ExceptionBoundary: React.FC<ExceptionBoundaryProps> = ({
children,
}: ExceptionBoundaryProps) => {
if (isLoading) {
return <Loading />
return <div>데이터 없음</div>
}

if (isError) {
return <div>에러 발생!</div>
}

if (isEmpty) {
return (
<NoData
title="해당 물건이 존재 하지 않습니다."
onClickButton={() => router.push('/cards/new')}
buttonContent="물건 등록하러 가기"
/>
)
return <div>데이터가 존재하지 않습니다.</div>
}

return (
<>
{children}
{isFetchingNextPage && <div>다음 페이지 불러오는중...</div>}
{isFetchingNextPage && <Loading />}
</>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/contexts/TanstackQueryContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const TanstackQueryGlobalConfig = {
retry: 3,
retryDelay: 1000,
suspense: true,
useErrorBoundary: true,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions src/hooks/api/queries/useCardsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export const useCardsQuery = ({
return lastPage.data.nextCursorId
},
staleTime: LIST_STALE_TIME,
gcTime: 0,
})
}

0 comments on commit b95eafc

Please sign in to comment.