gpt4 book ai didi

javascript - 状态未与 localStorage 同步

转载 作者:行者123 更新时间:2023-11-28 03:42:33 28 4
gpt4 key购买 nike

我正在使用 ngrx-store-localstorage 包来同步 localstorage 和 ngrx/store 之间的状态。我按照 Github 上显示的方式进行了设置,但它不起作用。我轻松登录,ngrx devtools 中的状态已更新,但 localstorage 中的 token 仍然为空,因为设置了初始状态。

这里是包、代码和所有内容的 github 链接: https://github.com/btroncone/ngrx-store-localstorage

这是我的代码:

export function localStorageSyncReducer(auth: ActionReducer<any>): ActionReducer<any> {
return localStorageSync({ keys: ['token'], rehydrate: true })(auth);
}
const metaReducers: Array<MetaReducer<any, any>> = [localStorageSyncReducer];

这也定了..

StoreModule.forRoot(reducers, { metaReducers })

我还尝试在末尾的括号中添加reducers.auth,然后它可以工作,但整个应用程序状态中只有“token”属性。

最佳答案

我会尝试将其放入我的代码中:

export const getAuthState = createFeatureSelector<State.auth>('auth')

然后将参数更改为:

{ keys: ['auth'], rehydrate: true }

这应该适用于整个州。

关于javascript - 状态未与 localStorage 同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48812561/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com