const fetch = url => dispatch => {
// ...
}
export const fetchQuestions = tag => (dispatch) => {
return dispatch(fetch(tag));
};
fetch
函数中的dispatch
是什么? url
是第一个单参数 fetch
函数。但是这里的 dispatch
是什么?
最佳答案
这相当于一个函数返回另一个函数。 IE。这个
const fetch = url => dispatch => {
// ...
}
相当于
const fetch = function(url) {
return function(dispatch) {
// ...
}
}
类似这样
export const fetchQuestions = tag => (dispatch) => {
return dispatch(fetch(tag));
};
相当于
export const fetchQuestions = function(tag) {
return function(dispatch) {
return dispatch(fetch(tag));
}
};
关于javascript - 链式箭头函数语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45147227/