Not working with Expo SDK 37 and v6 redux-persist
hirbod opened this issue · comments
I wasn't able to get this work with v6 and redux-persist. Not sure of there is a bug in redux-persist or if this component needs an update to work with v6
"redux-persist failed to create sync storage, failing back to noop storage" when I try to pass this component here as storage.
Works perfectly fine with v5
I could not reproduce. Are you specifying the correct storage option for persistConfig
(v6 breaking change)? I attached a working prototype with expo
37 and redux-persist
6.
// store.js
import {createStore} from "redux";
import { persistReducer, persistStore } from "redux-persist";
import ExpoFileSystemStorage from "redux-persist-expo-filesystem"
const rootReducer = (state = {val: 5}, action) => {
switch (action.type) {
case "INCREMENT":
return {val: state.val + 1};
case "DECREMENT":
return {val: state.val - 1};
default:
return state;
}
}
const persistConfig = {
key: "root",
storage: ExpoFileSystemStorage
};
const persistedReducer = persistReducer(persistConfig, rootReducer)
export const store = createStore(persistedReducer);
export const persistor = persistStore(store);
// App.js
import * as React from 'react';
import {Button, StyleSheet, View} from 'react-native';
import {connect, Provider} from "react-redux";
import {PersistGate} from "redux-persist/integration/react";
import {persistor, store} from "./store";
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
const ConnectedButton = connect(
(state) => {
return {val: state.val};
},
(dispatch) => ({
increment: () => {
dispatch({type: "INCREMENT"});
}
})
)(({val, increment}) => {
return <Button title={String(val)} onPress={increment}/>
});
export default function App(props) {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<View style={styles.container}>
<ConnectedButton />
</View>
</PersistGate>
</Provider>
);
}
Might this error occur since I am trying to update a project, which already have data? I'm not the only one complaining, there are some also at redux-persit repo with the same issue I have. Beside that, I've done the same like you
import { createStore } from "redux";
import { persistStore, persistReducer } from "redux-persist";
//import storage from "redux-persist/lib/storage"; // defaults to localStorage for web and AsyncStorage for react-native
import ExpoFileSystemStorage from "redux-persist-expo-filesystem";
import reducer from "./reducer";
const persistConfig = {
key: "root",
storage: ExpoFileSystemStorage,
};
const persistedReducer = persistReducer(persistConfig, reducer);
export const store = createStore(persistedReducer);
export const persistor = persistStore(store);
I'm not sure where this error happens...
I tried downgrading and upgrading the redux-persist
version and it did not lose track of my persisted value. Was the storage option changed recently? Or expo updated?
No, wasn't changed, I also had the correct storage option for persistConfig since SDK 36.
I tried this change 2-3 months ago (to v6) and now, retried after upgrading to SDK 37. Not working though.
I think that your lib is not causing the issues, more likely that v6 is breaking something internal.
It's working for me with SDK 37 and redux-persist v6...