Skip to content

Commit

Permalink
fix: 사용자 정보 로드된 후 header rerendering
Browse files Browse the repository at this point in the history
  • Loading branch information
uiop5809 committed Sep 2, 2024
1 parent a7247aa commit 33e4ff2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/components/common/Header.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -32,6 +30,12 @@ const Header = () => {
}
}, [pathname])

useEffect(() => {
if (state === 'hasValue' && userInfo) {
// 사용자 정보가 로드된 후에 헤더를 다시 렌더링
}
}, [state, userInfo])

const handleCategoryClick = (path: string) => {
if (!userInfo) {
showToast('로그인이 필요한 서비스입니다')
Expand Down
4 changes: 3 additions & 1 deletion src/service/user/LoadUserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 33e4ff2

Please sign in to comment.