Chained Arrow function syntax

后端 未结 4 1267
野的像风
野的像风 2021-02-19 20:08
const fetch = url => dispatch => {
  // ...
}

export const fetchQuestions = tag => (dispatch) => {
  return dispatch(fetch(tag));
};

What

4条回答
  •  独厮守ぢ
    2021-02-19 20:58

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

提交回复
热议问题