我在ReactJS中有一个crud应用程序,它使用redux-persist,在Chrome中可以正常工作。redux persist版本是v6。
当我在Firefox 78.0.2中运行应用程序时,控制台返回以下错误:
> redux-persist failed to create sync storage. falling back to noop storage.我在我的app.js中使用了localStorage,但移除并重新构建了应用程序:在没有调用火狐中的localStorage的情况下,应用程序会构建,但不会持久。在这两种情况下,Chrome都没有问题。
我提供了一些关于React-native的答案,但到目前为止还没有找到ReactJS的主题。
这里有人遇到过同样的问题吗?
下面是我的代码:
Package.JSON:
"devDependencies": {
...
},
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.0",
"react-uid": "^2.3.0",
"redux": "^4.0.5",
"redux-persist": "^6.0.0"
},
"browserslist": [
...
]
}Index.HTML:
import React from 'react';
import ReactDOM from 'react-dom';
import { persistStore } from 'redux-persist';
import { PersistGate } from 'redux-persist/lib/integration/react';
import { Provider } from 'react-redux';
import { configureStore } from './store';
import App from './App.js';
const store = configureStore();
const persistor = persistStore(store);
ReactDOM.render(
<Provider store={store}>
<PersistGate
loading={<div>Loading app..</div>}
persistor={persistor}>
<App />
</PersistGate>
</Provider>,
document.querySelector('#root'),
);Store.JS:
import { createStore, combineReducers } from 'redux';
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';
import { articles } from './services/actionReducer';
const reducers = {
articles,
};
const persistConfig = {
key: 'root',
storage,
stateReconciler: autoMergeLevel2,
}
const rootReducer = combineReducers(reducers);
const persistedReducer = persistReducer(persistConfig, rootReducer);
export const configureStore = () => createStore(
persistedReducer,
window.__REDUX_DEVTOOLS_EXTENSION__ &&
window.__REDUX_DEVTOOLS_EXTENSION__(),
);发布于 2020-07-16 17:51:27
在redux-persist v6中,您尝试按如下方式进行更改:
import storage from 'redux-persist/lib/storage';
import AsyncStorage from '@react-native-community/async-storage';
const persistConfig = {
//...
storage,
}
=>
const persistConfig = {
//...
storage: AsyncStorage,
}https://stackoverflow.com/questions/62931844
复制相似问题