Skip to content

Commit

Permalink
feat: LoadUserInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
uiop5809 committed Sep 2, 2024
1 parent c7a7c91 commit 9e174d8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import localFont from 'next/font/local'
import ReactQueryProviders from '@/hooks/useReactQuery'
import Toaster from '@/components/common/Toaster'
import { WebSocketProvider } from '@/hooks/useSocket'
import LoadUserInfo from '@/service/user/LoadUserInfo'

const pretendard = localFont({
src: '../../public/fonts/PretendardVariable.woff2',
Expand Down Expand Up @@ -39,6 +40,7 @@ export default function RootLayout({
<link rel="icon" href="/images/common/cat_logo.svg" sizes="any" />
<body className={`${pretendard.variable} font-pretendard`}>
<Recoil>
<LoadUserInfo />
<WebSocketProvider>
<ReactQueryProviders>
<main className="py-3 px-5 sm:px-7% md:px-10% ">
Expand Down
31 changes: 31 additions & 0 deletions src/service/user/LoadUserInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client'

import { useEffect } from 'react'
import { useRecoilState } from 'recoil'
import { userInfoState } from '@/recoil/UserInfo'
import UserService from './UserService'

const LoadUserInfo = () => {
const [userInfo, setUserInfo] = useRecoilState(userInfoState)

useEffect(() => {
const fetchUserInfo = async () => {
try {
const response = await UserService.fetchUserInfo()
if (response.data) {
setUserInfo(response.data)
}
} catch (error) {
console.error('Failed to load user info:', error)
}
}

if (!userInfo) {
fetchUserInfo()
}
}, [userInfo, setUserInfo])

return null
}

export default LoadUserInfo

0 comments on commit 9e174d8

Please sign in to comment.