Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法使用redux persist保存redux状态_Javascript_Ecmascript 6_Redux_React Redux_Redux Persist - Fatal编程技术网

Javascript 无法使用redux persist保存redux状态

Javascript 无法使用redux persist保存redux状态,javascript,ecmascript-6,redux,react-redux,redux-persist,Javascript,Ecmascript 6,Redux,React Redux,Redux Persist,我目前正在我的react redux应用程序中使用redux persist to persistent data storage。我已经根据你的要求设置好了。我已经用npx create-react-app在一个单独的项目上测试了它。持久性存储器工作正常 当我将其集成到实际工作项目中时,状态保存不起作用。有人能帮我吗 这是my store.js: 从'redux'导入{createStore,applyMiddleware,compose}; 从“react router redux”导入{r

我目前正在我的react redux应用程序中使用redux persist to persistent data storage。我已经根据你的要求设置好了。我已经用
npx create-react-app
在一个单独的项目上测试了它。持久性存储器工作正常

当我将其集成到实际工作项目中时,状态保存不起作用。有人能帮我吗

这是my store.js:

从'redux'导入{createStore,applyMiddleware,compose};
从“react router redux”导入{routerMiddleware};
从“redux thunk”导入thunk;
从“./reducers”导入rootreducer;
//导入持久性重复状态
从“redux persist”导入{persistStore,persistReducer}
从“redux persist/lib/storage”导入存储//默认为用于web的本地存储
const中间件=[thunk,routerMiddleware(历史)];
常量initialState={};
//重复使用持久化的配置
常量persistConfig={
键:'根',
存储
}
const persistedReducer=persistReducer(persistConfig,rootReducers)
函数composeWithApplyMiddleware(){
如果(窗口。\uuuu REDUX\u开发工具\uuuu扩展){
返回compose(applyMiddleware(…中间件),窗口;
}
返回compose(applyMiddleware(…中间件));
}
const createMyStore=()=>
createStore(
坚持不懈的教育者,
初始状态,
ComposeWithApplyMiddleware(),
);
让persistor=persistStore(createMyStore());
导出默认createMyStore();
index.js:
从“React”导入React;
从'react dom'导入{render};
从'react redux'导入{Provider};
从“react router redux”导入{syncHistoryWithStore};
从“react Router”导入{Router,Route,browserHistory};
从“随机id”导入随机id;
导入“normalize.css/normalize.css”;
导入“plottable/plottable.css”;
从“./store”导入存储;
从“./containers/Auth/Signin”导入SignInContainer;
从“./containers/Auth/Signup”导入SignUpContainer;
从“/containers/Auth/ForgotPassword”导入ForgotPasswordContainer;
从“./containers/Auth/ResetPassword”导入ResetPasswordContainer;
从“/containers/Auth/CompleteSignup”导入CompleteSignupContainer;
从“./containers/Users/List”导入UsersListContainer;
从“./containers/Endpoints/CreateEndpoint”导入CreateEndpointContainer;
从“./containers/TestMessages”导入TestMessagesContainer;
从“./containers/Dashboard”导入仪表板;
从“/actions/initialize”导入初始化;
从“./containers/Setting/Main”导入设置;
const root=document.getElementById('root');
const history=syncHistoryWithStore(浏览器历史记录,存储);
常数rand=RandomID(16,'A0');
setItem('authStateKey',rand);
const reduxOauthConfig={
后端:{
apiUrl:'http://0.0.0.0:4000“,//TODO:在此处更改后端URL
signOutPath:null,//添加注销路径以销毁会话令牌
tokenValidationPath:“/svr/ping”,
AuthProviderPath:{
facebook:“/svr/auth/facebook”,
github:“/svr/auth/github”,
gitlab:'/svr/auth/gitlab',
谷歌:'/svr/auth/google',,
twitter:“/svr/auth/twitter”,
},
},
};
const requireAuth=(下一个状态,替换)=>{
const state=store.getState();
const isSignedIn=state.auth.authUser.isSignedIn;
//const isSignupCompleted=state.auth.authUser.isSignupCompleted;
//在用户可以做任何事情之前,先完成注册
//如果(!isSignupCompleted&&nextState.location.pathname!=='/complete signup'){
//替换({
//路径名:'/complete signup',
//状态:{nextPathname:nextState.location.pathname},
//   });
// }
如果(!isSignedIn){
替换({
路径名:'/sign',
状态:{nextPathname:nextState.location.pathname},
});
}
};
const publicOnly=(下一个状态,替换)=>{
const state=store.getState();
const isSignedIn=state.auth.authUser.isSignedIn;
如果(伊西涅丁){
替换({
路径名:“/”,
状态:{nextPathname:nextState.location.pathname},
});
}
};
dispatch(初始化(reduxOauthConfig))。然后(
() => {
渲染(
,根,
);
},
);
reducers/index.js:

从'redux'导入{combinereducer};
从“react router redux”导入{routerReducer};
从“/message”导入消息;
从“./users”导入用户;
从“./endpoints”导入终结点;
从“/”导入烤面包;
从“/auth”导入身份验证;
导出默认合并器({
路由:routerReducer,
用户,
端点,
ui:干杯,
聊天室:留言,
啊,,
});

谢谢您的关注。

我遇到了这样的问题,所以我制定了自己的解决方案。请看一看,谢谢您的关注。我已经检查了您评论的链接,有很多令人印象深刻的方法来处理持久状态。但是我决定使用redux persist,因为它支持加密、压缩、,过期时间设置和状态协调。我在单独的新项目中测试了该库,它工作正常。是否也使用了redux persist?否。我提出了自己的解决办法