2017-07-16 20 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) –