优化用户数据初始化时机
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user