[RN][Redux-Persist] AutoRehydrate is not a function

前端 未结 2 630
陌清茗
陌清茗 2021-02-20 02:10

I am using redux-persist 5.5.0 When I debug my react native app, Error say \"autoRehydrate is not a function\" my source code here, give me help please

相关标签:
2条回答
  • 2021-02-20 02:39

    If using the above method, the error: Object(...) is not a function comes then try using: const store = createStore( persistedReducer, applyMiddleware(thunk ,logger) );

    0 讨论(0)
  • 2021-02-20 02:52

    redux-persist 5.x has changes in API and autoRehydrate no longer been used. Below is the way I use redux-persist now.

    import React, {Component} from 'react';
    import {Provider} from 'react-redux';
    import {createStore, applyMiddleware, compose} from 'redux';
    import {PersistGate} from 'redux-persist/lib/integration/react';
    import {persistStore, persistReducer} from 'redux-persist';
    import storage from 'redux-persist/lib/storage';
    import Thunk from 'redux-thunk';
    import Router from './Router';
    import reducers from './reducers';
    
    const persistConfig = {
        key: 'root',
        storage: storage,
    };
    const persistedReducer = persistReducer(persistConfig, reducers);
    
    const store = compose(persistedReducer, {}, composeEnhancers(applyMiddleware(Thunk)));
    
    class App extends Component {
        render() {
            const persistor = persistStore(store);
            return (
                <Provider store={store}>
                    <PersistGate persistor={persistor}>
                        <Router />
                    </PersistGate>
                </Provider>
            );
        }
    }
    
    export default App;
    
    0 讨论(0)
提交回复
热议问题