优化用户数据初始化时机

This commit is contained in:
2025-11-18 19:16:24 +08:00
parent 5b1dae6e6c
commit fa6a4e5121
19 changed files with 52 additions and 52 deletions

View File

@@ -1,5 +1,4 @@
'use client'
import {User} from '@/lib/models'
import {createContext, ReactNode, useContext, useEffect, useRef} from 'react'
import {StoreApi} from 'zustand/vanilla'
import {useStore} from 'zustand/react'
@@ -38,16 +37,20 @@ export function useClientStore<T>(selector: (store: ClientStore) => T) {
}
export type ProfileProviderProps = {
user: User | null
children: ReactNode
}
export default function StoresProvider(props: ProfileProviderProps) {
// 用户信息
const profile = useRef<StoreApi<ProfileStore>>(null)
if (!profile.current) {
console.log('📦 create profile store')
profile.current = createProfileStore(props.user)
profile.current = createProfileStore()
}
const profileStore = useRef(useStore(profile.current))
useEffect(() => {
profileStore.current.refreshProfile()
}, [])
const layout = useRef<StoreApi<LayoutStore>>(null)
if (!layout.current) {