javascript - 链式箭头函数语法

标签 javascript reactjs

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/

相关文章:

javascript - 从菜单中下拉空选择

javascript - javascript 中的函数只能运行一次

javascript - React JS 自定义侧边栏导航

reactjs - Next.js 渲染问题

javascript - 我应该在 useEffect 钩子(Hook)中使用 IIFE 吗?

javascript - Material-ui 和 typescript 没有重载匹配这个调用

javascript - 在 ios 应用程序中发送包含 javascript 的 html 电子邮件

javascript - 将点击功能更改为 Keydown() Keycode =32

javascript - React Redux 应用程序中 Windows 10 上的 Jest "No tests found, exiting with code 1"错误

javascript - 使用 Jest/Enzyme 和 Axios 测试 React 组件