Verric
Verric

Reputation: 1094

Redux-thunk dispatch is not a function

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) };
}

Upvotes: 3

Views: 7754

Answers (1)

aw04
aw04

Reputation: 11177

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
}

Upvotes: 9

Related Questions