From 33e4ff200ec6739be2a5e598ac7c1cd8623e2c69 Mon Sep 17 00:00:00 2001 From: parkyejin Date: Tue, 3 Sep 2024 01:45:49 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EB=A1=9C=EB=93=9C=EB=90=9C=20=ED=9B=84=20header=20?= =?UTF-8?q?rerendering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/Header.tsx | 10 +++++++--- src/service/user/LoadUserInfo.tsx | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/common/Header.tsx b/src/components/common/Header.tsx index dee7771..11d975e 100644 --- a/src/components/common/Header.tsx +++ b/src/components/common/Header.tsx @@ -1,7 +1,5 @@ -'use client' - -import dynamic from 'next/dynamic' import React, { useState, useEffect } from 'react' +import dynamic from 'next/dynamic' import Image from 'next/image' import { useToast } from '@/hooks/useToast' import { useRecoilValueLoadable } from 'recoil' @@ -32,6 +30,12 @@ const Header = () => { } }, [pathname]) + useEffect(() => { + if (state === 'hasValue' && userInfo) { + // 사용자 정보가 로드된 후에 헤더를 다시 렌더링 + } + }, [state, userInfo]) + const handleCategoryClick = (path: string) => { if (!userInfo) { showToast('로그인이 필요한 서비스입니다') diff --git a/src/service/user/LoadUserInfo.tsx b/src/service/user/LoadUserInfo.tsx index b8a1480..85e098b 100644 --- a/src/service/user/LoadUserInfo.tsx +++ b/src/service/user/LoadUserInfo.tsx @@ -12,7 +12,9 @@ const LoadUserInfo = () => { const fetchUserInfo = async () => { try { const response = await UserService.fetchUserInfo() - setUserInfo(response.data) + if (response.data) { + setUserInfo(response.data) + } } catch (error) { console.error('Failed to load user info:', error) }