整合' react-thunk':'不能将一个类称为一个函数'

时间:2016-12-13 10:54:32

标签: javascript reactjs redux-thunk

如何解决?

composeWithDevTools(applyMiddleware()) // work
composeWithDevTools(applyMiddleware(thunk)) // don't work

控制台错误消息:

Uncaught TypeError: Cannot call a class as a function

代码:

import { createStore, applyMiddleware } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import thunk from 'react-thunk';

createStore(reducer, composeWithDevTools(applyMiddleware(thunk)));

2 个答案:

答案 0 :(得分:0)

import { createStore, applyMiddleware, compose } from 'redux';
import { browserHistory } from 'react-router';
import { routerMiddleware } from 'react-router-redux';
import reducers from '../reducers/';
import thunk from 'redux-thunk';

const middlewares = [thunk, routerMiddleware(browserHistory), apiMiddleware];

const enhancers = compose(
  applyMiddleware(...middlewares),
);

const store = createStore(reducers, enhancers);


export default store;

答案 1 :(得分:0)

代替

import thunk from 'react-thunk';

必须是

import thunk from 'redux-thunk';