Skip to content

Commit

Permalink
💄 style: 优化第一次水合逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Aug 10, 2023
1 parent 226a875 commit fefae61
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/store/session/hooks/useSessionHydrated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { useEffect, useState } from 'react';
import { useSessionStore } from '@/store/session';

export const useSessionHydrated = () => {
const [isInit, setInit] = useState(false);
// 根据 sessions 是否有值来判断是否已经初始化
const hasInited = !!Object.values(useSessionStore.getState().sessions).length;

const [isInit, setInit] = useState(hasInited);

useEffect(() => {
const hasRehydrated = useSessionStore.persist.hasHydrated();

if (hasRehydrated) {
if (hasRehydrated && !isInit) {
setInit(true);
}
}, []);
Expand Down

0 comments on commit fefae61

Please sign in to comment.