In the following function, where does dispatch come from and what is the flow of control?
export const getContacts = () => async (dispatch) => {
const res = await axios.get("http://jsonplaceholder.typicode.com/users");
dispatch({
type: GET_CONTACTS,
payload: res.data,
});
};
I understand basic arrow functions, but what actually happens when I call getContacts(). Since I am not passing in anything, where does dispatch come from? Does this come from thunk? I did not import thunk into this file which is why I am confused. This is the whole file:
import { GET_CONTACTS, ADD_CONTACT, DELETE_CONTACT } from "./types";
import axios from "axios";
// the following returns the objects that we want to push to the dispatch in contactRedcuer
export const getContacts = () => async (dispatch) => {
const res = await axios.get("http://jsonplaceholder.typicode.com/users");
dispatch({
type: GET_CONTACTS,
payload: res.data,
});
};