首页 > 解决方案 > 连接 Redux devtools 和 Thunk 中间件到 store

问题描述

我正在尝试将 redux-devtools 连接到我的商店,但我不断收到以下错误:“看起来您正在将多个商店增强器传递给 createStore()。这是不支持的。相反,将它们组合成一个函数错误。 "

*使用 Thunk 作为中间件。

尝试使用增强器,但我仍然遇到不同的错误。

帮助将不胜感激。

这就是我的商店的样子:

import {createStore,applyMiddleware} from 'redux';
import thunk from 'redux-thunk'

const initialState={
 bla:"",
 bla:"",
 bla:"",
}

const reducer = (state= initialState, action)=>{
 bla bla bla..
 actions...
}


const store= createStore(reducer,applyMiddleware(thunk))

export default store;

标签: reactjsreduxredux-devtools-extension

解决方案


文档

    import { createStore, applyMiddleware, compose } from 'redux';

    const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

    const store = createStore(reducer, composeEnhancers(applyMiddleware(...middleware));
  ));

推荐阅读