如何解决“未捕获的TypeError:调度不是函数”?

时间:2019-03-31 02:56:04

标签: ruby-on-rails reactjs redux

当尝试在窗口上执行分派操作时,我遇到此错误:“未捕获的TypeError:分派不是函数”。

我仔细检查了语法。

Uncaught TypeError: dispatch is not a function
    at Object.eval (spot_actions.js?27ea:12)
    at Object.<anonymous> (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:3412)
    at fire (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:3233)
    at Object.fireWith [as resolveWith] (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:3363)
    at done (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:9841)
    at XMLHttpRequest.callback (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:10312)
export const fetchAllSpots = () => dispatch => (
    APIUtil.fetchAllSpots().then(spots => 
    dispatch(receiveAllSpots(spots)))
);

const receiveAllSpots = payload => ({
    type: RECEIVE_ALL_SPOTS,
    payload
});
window.fetchAllSpots = fetchAllSpots();

2 个答案:

答案 0 :(得分:1)

您要向路由器连接中添加dispatch吗? 像这样:

export default connect(mapStateToProps, dispatch => ({
  dispatch, ComponentNameHere})) (ComponentNameHere)

答案 1 :(得分:0)