发送请求中的数据

send the data in the request

在这段代码中,我试图将数据发送到请求中,并且正在发送的数据存在并在控制台中打印出来,但我的问题出在“切片”文件中,就像它一样不获取数据并打印它不存在

我该如何解决我的问题?

slice.js:

export const assignToUser = createAsyncThunk(
  "invoicesApp/invoice/assignToUser",
  async ({ id, userId, assignmentNote }, { dispatch }) => {
    console.log("hi in new function");
    console.log("invoiceId, userId, message", id, userId, assignmentNote);
    const response = await axios
      .post(`/invoices/flow/${id}/assign-to-user`, { userId, assignmentNote })
      .catch((error) => {
        console.log("error response: ", error);
      });
    const data = await response.data.data;
    console.log("approve invoices: ", data);
    dispatch(getInvoices());
    return data;
  }
);

[assignToUser.fulfilled]: (state, action) => {
      console.log(" action.payload: ", action.payload);
      action.payload;
    },

called.js:

        <Button
              onClick={(ev) => {
                //here is print correct 
                console.log(
                  "I am inside function: ",
                  "id: ",
                  id?.id,
                  ",users id: ",
                  userId,
                  ",message:",
                  message
                );
               dispatch(assignToUser({ invoiceId, userId, assignmentNote }));
                // assignToUserToApproveInvoiceHandleClick(ev);
                handleAssignToUserDialogClose();
              }}
              style={{ color: "#212529", fontWeight: 500 }}
              color="primary"
              autoFocus
            >
              Assign to approve
            </Button>

这是回复的形式:

为什么要为 Slice.js 文件中的 userId 添加 {}

async (invoiceId, { userId, message }, { dispatch }) => {

那是一个物体吗?您是否要为 userId 解构对象?

不应该像下面这样吗?

async (invoiceId, userId, message, { dispatch }) => {

检查documentation中的基本示例。不确定你是如何配置你的 redux 的。如果您在沙箱上分享一个可重现的示例,那就太好了。