-
{postData.writer.nickname}
- {postData.isWriter && (
+
{postData?.writer?.nickname}
+ {postData?.isWriter && (
{
setOpen(true);
- setDeleteId(String(postData.postId));
+ setDeleteId(String(postData?.postId));
setCategory('post');
}}
className="text-gray-500 text-sm font-normal underline cursor-pointer">
@@ -87,13 +88,13 @@ const PostDetail = () => {
{/* 제목자리 */}
-
{postData.title}
+
{postData?.title}
{/* 컨텐츠 내용자리 */}
-
{postData.content}
+
{postData?.content}
{/* 사진자리 */}
- {(postData.images?.length as number) > 0 ? (
+ {(postData?.images?.length as number) > 0 ? (
{postData.images?.map((image: string, i: number) => (
@@ -117,10 +118,10 @@ const PostDetail = () => {
{/* 일자 */}
- {formatDate(postData.createdDate)}
+ {formatDate(postData?.createdDate)}
{/* 시간 */}
-
{formatTime(postData.createdDate)}
+
{formatTime(postData?.createdDate)}
{/* 좋아요 조회수 자리 */}
@@ -128,10 +129,10 @@ const PostDetail = () => {
{/* 좋아요 */}
{
- if (postData.isLiked) {
- cancelLikeMutate(postData.postId);
+ if (postData?.isLiked) {
+ cancelLikeMutate(postData?.postId);
} else {
- registerLikeMutate(postData.postId);
+ registerLikeMutate(postData?.postId);
}
}}
className="flex items-center justify-center gap-1 cursor-pointer">
@@ -139,7 +140,7 @@ const PostDetail = () => {
좋아요
-
{postData.likeCount}
+
{postData?.likeCount}
@@ -151,7 +152,7 @@ const PostDetail = () => {
조회수
-
{postData.viewCount}
+
{postData?.viewCount}
@@ -159,4 +160,25 @@ const PostDetail = () => {
);
};
-export default PostDetail;
+export default WrapErrorBoundary;
+
+function WrapErrorBoundary() {
+ return (
+
+
+
+
+ 글을 가져오는 중 일시적인 오류가 발생했습니다.
+
+
+ 잠시 후 다시 시도해주세요
+
+
+
+
+ );
+}
diff --git a/src/components/shared/ErrorBoundary.tsx b/src/components/shared/ErrorBoundary.tsx
new file mode 100644
index 0000000..75263ef
--- /dev/null
+++ b/src/components/shared/ErrorBoundary.tsx
@@ -0,0 +1,35 @@
+import React, { ErrorInfo } from 'react';
+
+interface Props {
+ children: React.ReactNode;
+ fallbackComponent?: React.ReactNode;
+}
+
+interface State {
+ hasError: boolean;
+}
+
+class ErrorBoundary extends React.Component