2017-07-16 58 views
0

所以我在容器做到这一点:mapDispatchToProps行动不是一个函数

const mapDispatchToProps = (dispatch) => { 
    return { 
    actions: bindActionCreators({fetchMarkers}, dispatch) 
    } 
} 

当道具在浏览器中登录我收到:

actions: { 
    fetchMakers: function() .... 
} 

,但是当我打电话this.props.actions.fetchMarkers(params)我得到以下错误:

Cannot read property 'fetchMarkers' of undefined

这使我疯了,请帮忙!

编辑:

操作:

export const fetchMarkers = (payload) => { 
    return { 
    type: actionTypes.fetchMarkers, 
    payload 
    } 
} 
+0

我们可以看到更多的,你怎么连在哪里你用吧? – Li357

+0

我会说你错误地导入了fetchMarkers,因为当你像你一样绑定它时,你应该能够用'this.props.actions();' –

回答

1

尝试这种情况:

import { fetchMarkers } from 'path_to_makers_action'; 

....Code of react component.... 

export default connent(null, { fetchMarkers }); 

而在组件使用:this.props.fetchMarkers()

+0

执行动作创建器我现在正在执行这个动作文件有问题 –

+0

你可以附加减少thunk中间件到你的项目什么会失去异步行动的所有权力。 [https://github.com/gaearon/redux-thunk](https://github.com/gaearon/redux-thunk) –