0

我想在我的useGlobalStore. 我想在那里处理(设置和获取)会话存储的数据。我浏览了文档,但找不到如何将我的createpersist功能组合在一起的答案。

这是我的useGlobalStore

interface Store extends HeatMapState, WeeklyOverviewState, MonthlyOverviewState, GlobalState, UserState {}

export const useGlobalStore = create<Store>(
    devtools((set, get, api) => ({
        ...heatMapSlice(set as SetState<HeatMapState>, get as GetState<HeatMapState>, api as StoreApi<HeatMapState>),
        ...weeklyOverviewSlice(
            set as SetState<WeeklyOverviewState>,
            get as GetState<WeeklyOverviewState>,
            api as StoreApi<WeeklyOverviewState>,
        ),
        ...monthlyOverviewSlice(
            set as SetState<MonthlyOverviewState>,
            get as GetState<MonthlyOverviewState>,
            api as StoreApi<MonthlyOverviewState>,
        ),
        ...globalStateSlice(set as SetState<GlobalState>, get as GetState<GlobalState>, api as StoreApi<GlobalState>),
        ...userStateSlice(set as SetState<UserState>, get as GetState<UserState>, api as StoreApi<UserState>),
    })),
) as UseBoundStore<Store, StoreApi<Store>>
4

1 回答 1

1

https://github.com/pmndrs/zustand#middleware

你可以在下面找到它How to pipe middlewares

const createStore = pipe(persistor, devtools, create)
create<Store>(....store )

这应该适用于您的情况

于 2022-01-28T14:07:31.670 回答