【问题标题】:Redux-thunk dispatch is not a functionRedux-thunk dispatch 不是一个函数
【发布时间】:2017-04-30 01:29:56
【问题描述】:

我有以下操作

export function getAllBooks() {
  return function(dispatch) {
     return axios.get('http://localhost:8080/books')
    .then(response => dispatch(retrieveBooks(response.data)));
  };
}

问题是当我调用此操作时,我进入了控制台

Uncaught (in promise) TypeError: dispatch is not a function 在 eval (eval at ...

那是.then(response => dispatch(retrieveBooks(response.data)));中的dispatch正在播放

我尝试删除除 redux-thunk 之外的所有其他中间件,但无济于事

动作的唯一使用地点是在

const mapDispatchToProps = (dispatch) => {
  return { fetchBooks : () => dispatch(getAllBooks) };
}

【问题讨论】:

  • 你检查过dispatch实际上是什么吗?
  • 然后记录dispatch对象

标签: redux redux-thunk


【解决方案1】:

您需要调用getAllBooks 动作创建者并将内部函数传递给dispatch

const mapDispatchToProps = dispatch => {
  return { fetchBooks: () => dispatch(getAllBooks()) } //note the dispatch call
}

【讨论】:

  • 谢谢你,我知道我很接近了:(
猜你喜欢
  • 2017-06-09
  • 2017-10-31
  • 2021-04-26
  • 1970-01-01
  • 2017-12-27
  • 1970-01-01
  • 2019-07-19
  • 2019-01-27
  • 2020-07-21
相关资源
最近更新 更多