Redux-thunk dispatch is not a function

7.7k views Asked by At

I have the following action

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

The issue is when i call this action, I get in the console

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

that is the dispatch in the .then(response => dispatch(retrieveBooks(response.data))); is playing up

I've tried removing all other middle-ware except redux-thunk to no avail

The only place the action is used is in

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

There are 1 answers

1
aw04 On BEST ANSWER

You need to call the getAllBooks action creator and pass the inner function to dispatch

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