简体   繁体   English

以反应最终形式单独提交组件

[英]seperate submit component in react-final-form

const Buttons = () => {

  return (
    <>
      <div>
        <button
          buttonType="submit"
          disabled={form.hasValidationErrors || form.pristine}
        >
          Save
        </button>

       </>
  );
};

export default Buttons;

I have used react-final-form to create form for my react form.我已经使用react-final-form form 为我的反应表单创建表单。 But I want to implement a seperate component for submit button.但我想为提交按钮实现一个单独的组件。 I need to have access to pristine but it gives me an error as there is not any form here in new component.我需要访问原始文件,但它给了我一个错误,因为新组件中没有任何表单。

Does anyone have any solution?有没有人有任何解决方案?

Have you tried send the form as a parameter to the Buttons component?您是否尝试将表单作为参数发送到Buttons组件? Also, I think you were missing a closing div in your code.另外,我认为您的代码中缺少一个结束 div。

const Buttons = ({form}) => {
    return (
      <>
        <div>
          <button
            buttonType="submit"
            disabled={form.hasValidationErrors || form.pristine}
          >
          Save
          </button>
        </div>
      </>
  );
};

export default Buttons;

As I use Typescript I do not know what is the type of form which i want to send it through props to my Buttons component.当我使用 Typescript 时,我不知道我想通过 props 将它发送到我的 Buttons 组件的表单类型是什么。 Also, II do not know if this is a right solution or not.另外,我不知道这是否是正确的解决方案。 Or does react-final-form has anything to help solving the issue?或者 react-final-form 有什么帮助解决问题的吗?

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

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