const fetch = url => dispatch => {
// ...
}
export const fetchQuestions = tag => (dispatch) => {
return dispatch(fetch(tag));
};
What is dispatch in the fetch function ? url is a first and single parameter fetch function. But what is dispatch here ?
This is equivalent to one function returning another. I.e. this
const fetch = url => dispatch => {
// ...
}
is equivalent to
const fetch = function(url) {
return function(dispatch) {
// ...
}
}
Similarly this
export const fetchQuestions = tag => (dispatch) => {
return dispatch(fetch(tag));
};
is equivalent to
export const fetchQuestions = function(tag) {
return function(dispatch) {
return dispatch(fetch(tag));
}
};
dispatch is the first and single parameter of the function returned by the url => ... function. With normal function syntax, it would be
const fetch = function(url) {
return function(dispatch) {...}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With