[RN][Redux-Persist] AutoRehydrate 不是一个函数 [英] [RN][Redux-Persist] AutoRehydrate is not a function

查看:68
本文介绍了[RN][Redux-Persist] AutoRehydrate 不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 redux-persist 5.5.0当我调试我的本机应用程序时,错误提示自动补水不是功能"我的源代码在这里,请给我帮助

"use strict";

import thunk from "redux-thunk";
import analytics from "./analytics";
import array from "./array";
import promise from "./promise";
import reducers from "../reducers";
import { createLogger } from "redux-logger";
import { applyMiddleware, createStore, compose } from "redux";
import { persistStore, autoRehydrate } from "redux-persist";
import { ensureCompatibility } from "./compatibility";
import { AsyncStorage } from "react-native";

const isDebuggingInChrome = false;

const logger = createLogger({
    predicate: (getState, action) => isDebuggingInChrome,
    collapsed: true,
    duration: true
});

const middleware = applyMiddleware(thunk, promise, array, analytics, logger);

async function configureStore(onComplete: ?() => void) {
    const didReset = await ensureCompatibility();
    const store = createStore(reducers, { /* TODO: Initial state */  }, compose(middleware, autoRehydrate()));

    persistStore(store, { storage: AsyncStorage }, _ => onComplete(didReset));

    if (isDebuggingInChrome) {
        window.store = store;
    }
    return store;
}

推荐答案

redux-persist 5.x 在 API 中进行了更改,不再使用 autoRehydrate.下面是我现在使用 redux-persist 的方式.

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;

这篇关于[RN][Redux-Persist] AutoRehydrate 不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆