Chained Arrow function syntax

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

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

What

4条回答
  •  轮回少年
    2021-02-19 20:49

    Its a shorter way of writing a function that returns another function. The arguments url and dispatch are arguments to the curryed function The ES5 equivalent of arrow function syntax would be

    function fetch(url) {
        return function(dispatch) {
             ....
        }
    }
    

    or with Arrow syntax as

    const fetch = (url) => {
        return (dispatch) => {
            // ... 
        }
    }
    

    Similarly you would have fetchQuestion written as

    export function fetchQuestions(tag) {
         return function(dispatch){
                return dispatch(fetch(tag));
         }
    }
    

    or with Arrow syntax as

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

提交回复
热议问题