Redux-thunk dispatch 不是函数

Ver*_*ric 2 redux redux-thunk

我有以下行动

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

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

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) };
}
Run Code Online (Sandbox Code Playgroud)

aw0*_*w04 7

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

const mapDispatchToProps = dispatch => {
  return { fetchBooks: () => dispatch(getAllBooks()) } //note the dispatch call
}
Run Code Online (Sandbox Code Playgroud)