刷新应用程序或重新进入应用程序时,直到清除异步存储时,reducer密钥才会反映在存储中

时间:2019-09-13 09:59:13

标签: javascript reactjs react-native redux redux-persist

我在“错误减少器”中添加了一些新密钥,但是当应用刷新或回到应用程序时,直到清除了应用的异步存储/本地存储,我才能在同一还原器下的redux存储中看到这些密钥。谁能帮助我,以便每当我刷新应用程序时,标志都会立即反映在我的商店中。

Reducer.js

"use-strict"

import { ERROR_CONSTANTS } from '../constants/errorConstants'

const initialState = {
    Error:
    {
        message: null,
        stack: null
    },
    UserFriendlyMessage: null,
    Dismissed: false,
    test:{a:1,b:2, c:2} // new key added
}

export default function errorReducer(state = initialState, action)
{
    switch(action.type){
        case ERROR_CONSTANTS.Add_Error_To_State:{
            return {
                ...state,
                Error:
                {
                    message: action.data.error.message,
                    stack: action.data.error.stack,
                    errorData: action.data.error.errorData
                },
                UserFriendlyMessage: action.data.userFriendlyMessage,
                Dismissed: false
            }
        }
        case ERROR_CONSTANTS.Clear_Error:{
            return initialState;
        }
        default:{
            return state;
        }
    }
}

configStore.js

'use strict';

/* React Native */
import { AsyncStorage } from 'react-native';

/* Officetrax */
import { createStore, applyMiddleware } from 'redux';
import app from './reducers';

/* Thunk */
import thunk from 'redux-thunk';
import { createMigrate, persistReducer, persistStore } from 'redux-persist'
/* Redux Storage */
import excludeSaveActionConstants from './constants/excludeSaveActionConstants';

/* Remote Redux Dev Tools */
import { composeWithDevTools } from 'remote-redux-devtools';

/* Redux Offline */
import { offline } from '@redux-offline/redux-offline';
import offlineConfig from '@redux-offline/redux-offline/lib/defaults';

/* Redux Logger */
import { createLogger } from 'redux-logger';

export default function configureStore() {




    let persistOptions = { ...offlineConfig, whitelist: excludeSaveActionConstants};

    const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || composeWithDevTools;
    // Create the store with middleware applied
    let store = createStore(app, composeEnhancers(
        applyMiddleware(thunk),
        offline(persistOptions)
    ));

    return store;
}

0 个答案:

没有答案