-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
배포시 서버측 Date값과 클라이언트측 Date값이 달라 Hydrate error가 발생하는 문제 수정
배포시 서버측 Date값과 클라이언트측 Date값이 달라 Hydrate error가 발생하는 문제 수정
- Loading branch information
Showing
16 changed files
with
106 additions
and
68 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Next.js: debug server-side", | ||
"type": "node-terminal", | ||
"request": "launch", | ||
"command": "yarn dev" | ||
}, | ||
{ | ||
"name": "Next.js: debug client-side", | ||
"type": "chrome", | ||
"request": "launch", | ||
"url": "http://localhost:3000" | ||
}, | ||
{ | ||
"name": "Next.js: debug full stack", | ||
"type": "node-terminal", | ||
"request": "launch", | ||
"command": "yarn dev", | ||
"serverReadyAction": { | ||
"pattern": "- Local:.+(https?://.+)", | ||
"uriFormat": "%s", | ||
"action": "debugWithChrome" | ||
} | ||
} | ||
] | ||
} |
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
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
|
||
import { useGetUserQuery } from "@hooks/query/user"; | ||
|
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 React, { useEffect, useState } from "react"; | ||
|
||
import { dateTimeParser } from "@utils/dateTimeParser"; | ||
|
||
interface IProps { | ||
date: string; | ||
className?: string; | ||
} | ||
|
||
const DateTime = ({ date, className }: IProps) => { | ||
const [formattedDate, setFormattedDate] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const formatted = dateTimeParser(date); | ||
|
||
setFormattedDate(formatted); | ||
}, []); | ||
|
||
if (!formattedDate) { | ||
return <span className="h-4 w-16 rounded-md bg-slate-300 dark:bg-slate-600" />; | ||
} | ||
|
||
return <span className={className}>{formattedDate}</span>; | ||
}; | ||
|
||
export default DateTime; |
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 |
---|---|---|
@@ -1,16 +1,24 @@ | ||
type Props = (date: string) => string; | ||
|
||
export const dateTimeParser: Props = (date) => { | ||
const diff = Math.ceil((new Date().getTime() - new Date(date).getTime()) / (1000 * 60 * 60)); | ||
const currentDate = new Date(); | ||
const inputDate = new Date(date); | ||
|
||
const dateTimeFormat = new Intl.DateTimeFormat("ko", { dateStyle: "long" }).format( | ||
new Date(date), | ||
); | ||
const timeDifference = currentDate.getTime() - inputDate.getTime(); | ||
const seconds = Math.floor(timeDifference / 1000); | ||
const minutes = Math.ceil(seconds / 60); | ||
const hours = Math.floor(minutes / 60); | ||
const days = Math.floor(hours / 24); | ||
|
||
const relativeTimeFormat = new Intl.RelativeTimeFormat("ko", { numeric: "auto" }).format( | ||
diff * -1, | ||
"hour", | ||
); | ||
if (days >= 1) { | ||
const year = inputDate.getFullYear(); | ||
const month = inputDate.getMonth() + 1; | ||
const day = inputDate.getDate(); | ||
|
||
return diff >= 24 ? dateTimeFormat : relativeTimeFormat; | ||
return `${year}년 ${month}월 ${day}일`; | ||
} | ||
|
||
if (hours >= 1) return `${hours}시간 전`; | ||
|
||
return `${minutes}분 전`; | ||
}; |
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