So I was using redux-persist in my react-native app to persist the state and everything is working fine.
For the reducer, I was using switch-case
to check for different action-types, and for the default, I was returning the state.
initialState = {
first: null,
second: null,
};
export default myReducer = (state = initialState, action) => {
switch (action.type) {
case ...:
... // Handling some cases which work fine
default:
return state;
}
};
This thing is working fine but if I replace state
with {...state}
in the default block, it doesn't persist the state.
Now how much I had understood is state = {...state}
so why is this not working.
Here is the persistConfig;
import AsyncStorage from "@react-native-async-storage/async-storage";
const persistConfig = {
key: "root",
storage: AsyncStorage,
};