首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >action.rehydrate不是一个函数

action.rehydrate不是一个函数
EN

Stack Overflow用户
提问于 2018-04-25 11:58:13
回答 3查看 3.1K关注 0票数 9

在我的控制台中,我一直收到以下错误,我不知道它是什么意思,为什么它是起源的。请在这件事上传播一些信息。

上面写着:

代码语言:javascript
复制
persistReducer.js:50 Uncaught TypeError: action.rehydrate is not a function
at _rehydrate (persistReducer.js:50)
at persistReducer.js:54

Package.json上的redux-persist版本:"^5.6.11“锁定版本:"5.9.1”

存储配置代码:

代码语言:javascript
复制
import thunk from 'redux-thunk';
import { persistStore } from 'redux-persist';
import { History, createBrowserHistory } from 'history';
import { createUserManager, loadUser } from "redux-oidc";
import { routerReducer, routerMiddleware } from 'react-router-redux';
import { createStore, applyMiddleware, compose, combineReducers, GenericStoreEnhancer, Store, StoreEnhancerStoreCreator, ReducersMapObject } from 'redux';

import * as StoreModule from './reducers';
import { ApplicationState, reducers } from './reducers';

import userManager from "./utils/userManager";

// Create browser history to use in the Redux store
const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href')!;
const history = createBrowserHistory({ basename: baseUrl });

export default function configureStore(history: History, initialState?: ApplicationState) {
    // Build middleware. These are functions that can process the actions before they reach the store.
    const windowIfDefined = typeof window === 'undefined' ? null : window as any;
    // If devTools is installed, connect to it
    const devToolsExtension = windowIfDefined && windowIfDefined.__REDUX_DEVTOOLS_EXTENSION__ as () => GenericStoreEnhancer;


    const createStoreWithMiddleware = compose(
        applyMiddleware(thunk, routerMiddleware(history)),
        devToolsExtension ? devToolsExtension() : <S>(next: StoreEnhancerStoreCreator<S>) => next
    )(createStore);

    // Combine all reducers and instantiate the app-wide store instance
    const allReducers = buildRootReducer(reducers);
    const store = createStoreWithMiddleware(allReducers, initialState) as Store<ApplicationState>;
    loadUser(store, userManager);

    // Enable Webpack hot module replacement for reducers
    if (module.hot) {
        module.hot.accept('./reducers', () => {
            const nextRootReducer = require<typeof StoreModule>('./reducers');
            store.replaceReducer(buildRootReducer(nextRootReducer.reducers));
        });
    }
    const persistor = persistStore(store);
    return { store, persistor };
}

function buildRootReducer(allReducers: ReducersMapObject) {
    return combineReducers<ApplicationState>(Object.assign({}, allReducers, { routing: routerReducer }));
}

// Get the application-wide store instance, prepopulating with state from the server where available.
const initialState = (window as any).initialReduxState as ApplicationState;
export const { store, persistor } = configureStore(history, initialState);
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-09-01 21:41:07

如果您正在使用本地主机并使用redux-devtools,请尝试选中扩展选项上的Access File Url复选框。

你可以通过在地址栏中输入chrome://extensions/或者进入设置并从左侧菜单中选择extensions来管理你的chrome扩展。

票数 26
EN

Stack Overflow用户

发布于 2018-06-07 07:24:28

当我使用redux devtools时,我得到了这个错误,删除它,它应该会消失。

代码语言:javascript
复制
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
票数 1
EN

Stack Overflow用户

发布于 2018-04-25 12:56:12

您的代码正在使用旧版redux-persist的API。

更新的接口请参考Basic Usage

代码语言:javascript
复制
import { persistStore, persistReducer } from 'redux-persist'

const persistConfig = {
  key: 'root',
  storage,
}

const allReducers = persistReducer(persistConfig, buildRootReducer(reducers));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50013837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档