0

I am using redux-offline, below is how I am creating my store


let customConfig = {
    ...offlineConfig,
    persistOptions:{
        key: 'root',
        transforms: [immutableTransform()],
    },
    returnPromises : false,
    persistCallback : () => {this.setState({rehydrated : true})}
};

const { middleware, enhanceReducer, enhanceStore } = createOffline(customConfig);
let middlewares = applyMiddleware(offlineCommitHandler,thunk,middleware,);
store = createStore(enhanceReducer(IndexReducer),undefined,compose(enhanceStore,middlewares,persistAutoRehydrate({log:true})));

I have multiple reducers.

The issue occurs only in rehydrating one reducer, for ex : reducerA

I placed a debugger in autoRehydrate

  • When opening the app first time it merges the data for reducerA
  • When opening the app second time inbound state for reducerA is null.
You Nguyen
  • 9,961
  • 4
  • 26
  • 52
Gokul
  • 82
  • 8

2 Answers2

0

I never did offline config but I ran into similiar problems with redux-persist. So first of all you want to make sure that your debugger and your device/emulator are not drifting away in time. This would cause me problems all the time, simply restarting the emulator and chrome tab which I was using for debugging would solve it. Second, you want to check if you don't have any errors in your reducer. In my case, I was not following the immutability pattern and that would sometimes cause redux not to persist my state, as it did not see any difference between the old state and the new state.

Annie Hill
  • 379
  • 3
  • 16
  • The issue exists in production build also. and for the errors in reducer currently i am not finding any errors in it, Can you tell me what was the error you made while you were facing the issue ? – Gokul Oct 11 '18 at 09:28
  • So say I have an array of objects and need to update 1 property of 1 object in that array. You need to create a copy of this object using the spread operator or object.assign and then change the property on the new object. Then you switch the object in the array once again using the spread operator and the array.slice function. My mistake was NOT creating a copy and modifying the object itself. Redux sees it as same object and therefore it will not update – Annie Hill Oct 11 '18 at 12:17
  • I am using ImmutableJS, to reduce the mutations i need to make, But i am not modifying the data in reducer, Only the redux init actions redux offline offline status action and Rehydrate actions are passed which i do not handle – Gokul Oct 11 '18 at 12:28
  • Thanks for the help Annie , Solved it! – Gokul Oct 12 '18 at 06:14
0

For anyone looking for answer to similar issue.

My issue was that the data i was trying to store was hitting the max storage limit for asyncStorage .

https://github.com/rt2zz/redux-persist/issues/199

I had to shift to using filestorage instead of asyncStorage to get redux persist store the data

Gokul
  • 82
  • 8