Skip to content

Commit

Permalink
fix: Hydration 불일치 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrin-byte committed Jan 6, 2025
1 parent 8937a2a commit 5e32212
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
25 changes: 14 additions & 11 deletions app/admin/(components)/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React, { useEffect, useState } from "react";
import Image from "next/image";
import classNames from "classnames";
import { useRouter, useSearchParams } from "next/navigation";
Expand All @@ -11,6 +11,7 @@ import {
subscribeLinkURL,
} from "@/admin/(consts)/sidebar";
import {
getLoginInfo,
getSelectedThemeId,
getStatus,
removeThemeId,
Expand All @@ -27,8 +28,6 @@ interface Theme {
}

interface Props {
adminCode: string;
shopName: string;
categories: Theme[];
selectedTheme: Theme;
handleClickSelected: (theme: Theme) => void;
Expand All @@ -45,12 +44,16 @@ export default function Sidebar(props: Props) {
const searchParams = useSearchParams();
const selectedThemeId = getSelectedThemeId();
const params = new URLSearchParams(searchParams.toString()).toString();
const {
adminCode = "",
shopName = "",
categories,
handleClickSelected,
} = props;
const { categories, handleClickSelected } = props;
const [loginInfo, setLoginInfo] = useState({
adminCode: "",
shopName: "",
});

useEffect(() => {
const { adminCode, shopName } = getLoginInfo(); // getLoginInfo로 값 가져오기
setLoginInfo({ adminCode, shopName }); // 상태 업데이트
}, []);

// const handleLogout = () => {
// removeAccessToken();
Expand Down Expand Up @@ -100,7 +103,7 @@ export default function Sidebar(props: Props) {
<div className="sidebar__shop-info">
<Image {...logoProps} className="sidebar__shop-logo" />
<span className="sidebar__shop-name">
{shopName?.replaceAll(`"`, "")}
{loginInfo.shopName?.replaceAll(`"`, "")}
</span>
</div>
<div className="sidebar__theme-title">우리 지점 테마</div>
Expand Down Expand Up @@ -164,7 +167,7 @@ export default function Sidebar(props: Props) {
<div className="sidebar__bottom">
<p className="sidebar__admin-code-title">관리자 코드</p>
<p className="sidebar__admin-code-value">
{adminCode?.replaceAll(`"`, "")}
{loginInfo.adminCode?.replaceAll(`"`, "")}
</p>
</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions app/admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function Admin() {
const isLoggedIn = useCheckSignIn();

const [selectedTheme, setSelectedTheme] = useSelectedTheme();
const { adminCode, shopName } = getLoginInfo();

const [toast, setToast] = useToastInfo();
const router = useRouter();
Expand Down Expand Up @@ -54,8 +53,6 @@ function Admin() {
}, [toast, setToast]);

const SidebarViewProps = {
adminCode,
shopName,
categories,
selectedTheme,
handleClickSelected,
Expand Down
2 changes: 0 additions & 2 deletions app/admin/AdminView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ interface Theme {
}

interface Props {
adminCode: string;
shopName: string;
categories: Theme[];
selectedTheme: Theme;
isOpen: boolean;
Expand Down

0 comments on commit 5e32212

Please sign in to comment.