Javascript 中一个箭头函数到另一个箭头函数的含义是什么?

What does an arrow function to another arrow function mean in Javascript?

在下面的函数中,dispatch是从哪里来的,控制流程是怎样的?

export const getContacts = () => async (dispatch) => {
  const res = await axios.get("http://jsonplaceholder.typicode.com/users");
  dispatch({
    type: GET_CONTACTS,
    payload: res.data,
  });
};

我了解基本的箭头函数,但是当我调用 getContacts() 时实际发生了什么。由于我没有传递任何东西,调度从何而来?这是来自thunk吗?我没有将 thunk 导入此文件,这就是我感到困惑的原因。这是整个文件:

import { GET_CONTACTS, ADD_CONTACT, DELETE_CONTACT } from "./types";
import axios from "axios";

// the following returns the objects that we want to push to the dispatch in contactRedcuer
export const getContacts = () => async (dispatch) => {
  const res = await axios.get("http://jsonplaceholder.typicode.com/users");
  dispatch({
    type: GET_CONTACTS,
    payload: res.data,
  });
};

What does an arrow function to another arrow function mean in Javascript?

第一个箭头函数将第二个箭头函数作为 return 值。

如果您不将参数传递给第一个参数(如在本例中)以形成闭包,这通常不是一件有用的事情。

I understand basic arrow functions, but what actually happens when I call getContacts(). Since I am not passing in anything, where does dispatch come from?

dispatch 在调用 returned 函数时出现,这在您共享的代码中不会发生。


const first = (argument_to_first) => 
    (argument_to_second) => console.log({
      argument_to_first,
      argument_to_second
    });

const second = first("Hello");

second("Goodbye");