react项目中添加了thunk为什么dispatch(fun())还是报错?

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

import thunk from 'redux-thunk'

import reducer from '../Reducer/index'

const composeEnhancers =

window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?

window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose;

const enhancer = composeEnhancers(

applyMiddleware(thunk)

);

const store = createStore(reducer, enhancer);

export default store;

这是store的配置 中间件使用了thunk

function mapdispatchtoprops(dispatch){

return{

setLoginState:dispatch(login(token))

}

}

export default connect(null,mapdispatchtoprops)(withRouter(Login));

这是component中的使用

const login = (token)=>{

return {

type:'login',token:token,loginStatus:true

}

}

const loginAction = (token) => dispatch =>{

if(Object.getOwnPropertyNames(token).length > 0 ){

dispatch(login(token))

}else{

return false;

}

}

export default {loginAction,login}

这是自定的action

在component在执行报错:

Uncaught TypeError: Object(...) is not a function

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问