简体   繁体   English

使用 mutator react final form 更新表单 state 时出错

[英]Getting an error while updating form state using mutator react final form

i am trying to update the values in the form state using react final form mutators by writing function below我正在尝试通过在下面编写 function 来更新 state 形式的值

const setProjectSelectedMutator = ([value], formState, tools) => {
tools.changeValue(formState, () => value && value.isSelectedInProject === true);
}; 

and then i am calling that mutate function like as below,然后我称之为变异 function 如下所示,

if (!once) {
    if (
      form &&
      values.spaceType.mechanicalData[mappedLibrarySourceArray] &&
      values.spaceType.mechanicalData[mappedLibrarySourceArray][index]
    ) {
      //  values.spaceType.mechanicalData[mappedLibrarySourceArray][
      //    index
      //  ].isSelectedInProject = true;
      form.mutators.setProjectSelectedMutator(
        values.spaceType.mechanicalData[mappedLibrarySourceArray][index].isSelectedInProject
      );
      setOnce(true);
    }
  }

i would like to set the boolean to true using the mutator function like as i am setting the same(mentioned in commented code) and getting an error like mutate is not a function .我想使用 mutator function 将 boolean 设置为 true,就像我设置相同(在注释代码中提到)并得到一个错误,如mutate is not a function

I am new to react final forms and could any one please suggest any idea or suggestion on this issue.我是对最终 forms 做出反应的新手,任何人都可以就这个问题提出任何想法或建议。

Thanks in advance提前致谢

I think you forgot the second parameter that has the name of the field.我认为您忘记了具有字段名称的第二个参数。 I'ved added the "SOME NAME" string to your code.我已将"SOME NAME"字符串添加到您的代码中。

const setProjectSelectedMutator = ([value], formState, tools) => {
tools.changeValue(formState, "SOME NAME", () => value && value.isSelectedInProject === true);
}; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM