javascript 函数内部传递的参数变为未定义

carvr3hs  于 2022-12-17  发布在  Java
关注(0)|答案(1)|浏览(120)
const onCellClick = p => {
    const policyId = p?.id;
    const updatedBy = p?.row?.updated_by;
    console.log(updatedBy, "updatedBy");
    applyPolicies(policyId, updatedBy);
  };

字符串
这是我使用pID和updatedBy进行API调用的另一个函数,在pID正常的情况下,updatedBy变为未定义。

export const useApplyPolicyMutation = () => {
  return useMutation(
    (pID, updatedBy) => {
      console.log(updatedBy, "updatedByinquery");
      console.log(pID, "pID");
      const workspaceId = getWS();
      const payload = {
        workspace_id: workspaceId,
        policy_id: pID,
        updated_by: updatedBy
      };
      customPost("/policymanagement/api/v1/auto-discover/add-policy", payload);
    }
mum43rcc

mum43rcc1#

useMutation只能接受一个参数作为有效负载,因此需要将其 Package 在一个对象中:

export const useApplyPolicyMutation = () => {
  return useMutation(
-    (pID, updatedBy) => {
+    ({ pID, updatedBy }) => {
- applyPolicies(policyId, updatedBy);
+ applyPolicies({ pID: policyId, updatedBy });

相关问题