Redux Persist การเติมน้ำไม่ทำงานบน Android

ฉันมีแอปที่ใช้ React Native & Expo แอป & Redux ของฉันยังคงทำงานได้ดีจนกว่าฉันจะหยุดกระบวนการของแอป หลังจากเปิดใหม่ redux ยังคงมีอยู่ ไม่สามารถเติมน้ำได้ (ไม่มีข้อผิดพลาด) และข้อมูลทั้งหมดที่บันทึกไว้ในร้านค้าจะสูญหาย

ไม่มีใครมีความคิดว่าฉันทำอะไรผิด? หรือบางทีฉันไม่ได้ตั้งค่าอะไร?

นี่คือการกำหนดค่าร้านค้าของฉัน

import { createStore, combineReducers, compose } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';

import appReducer from '../scenes/App/app.reducer';
//...other reducers
import actionReducer from '../lib/managers/action.reducer';

const reducer = combineReducers({
  app: appReducer,
  //...other reducers
  action: actionReducer,
});

const persistConfig = {
  key: 'root',
  storage,
  blacklist: ['log', 'action'],
  stateReconciler: autoMergeLevel2,
};

const persistedReducer = persistReducer(persistConfig, reducer);
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

function configureStore() {
  return createStore(persistedReducer, composeEnhancers());
}

person Greg    schedule 31.10.2018    source แหล่งที่มา


คำตอบ (1)


คุณจะบูตแอปของคุณได้อย่างไร? คุณใช้ react-native-navigation หรือไม่ หรือวิธีการรูตอื่น ๆ ?

การกำหนดค่านี้ดูเหมือนจะไม่ถูกต้อง แต่ปัญหาอาจอยู่ที่วิธีการห่อรากของคุณ (บางทีคุณควรแชร์บิตนั้นด้วย)

ดูจากเอกสาร redux-persist เกี่ยวกับวิธีล้อมรากของคุณด้วย PersistGate:

import { PersistGate } from 'redux-persist/integration/react'

// ... normal setup, create store and persistor, import components etc.

const App = () => {
  return (
    <Provider store={store}>
      <PersistGate loading={null} persistor={persistor}>
        <RootComponent />
      </PersistGate>
    </Provider>
  );
};
person Jojo    schedule 16.01.2019