【问题标题】:How can i fix "Uncaught TypeError: dispatch is not a function"?如何修复“未捕获的 TypeError:调度不是函数”?
【发布时间】:2019-08-21 13:52:36
【问题描述】:

我在尝试在窗口上执行调度操作时遇到此错误:“未捕获的 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();

【问题讨论】:

  • 这里是util调用函数:export const fetchAllSpots = () => ($.ajax({ method: 'GET', url: '/api/spots', }) );跨度>
  • 你还没有将 dispatch 定义为函数
  • 您能详细说明一下吗?谢谢!
  • 您是否将 redux-thunk 作为中间件连接到您的 redux 存储?

标签: ruby-on-rails reactjs redux


【解决方案1】:

您是否将dispatch 添加到路由器连接? 类似的东西:

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

【讨论】:

    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2019-12-13
      • 2016-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-26
      • 2017-05-15
      相关资源
      最近更新 更多