Redux-thunk dispatch 不是函数

Redux-thunk dispatch is not a function

我有以下操作

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 at eval (eval at ...

也就是dispatch中的.then(response => dispatch(retrieveBooks(response.data)));正在打起来

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

唯一使用该动作的地方是

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

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

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