0

This is my react function component

import "./styles.css";
import { Form, Button } from "antd";

export default function App() {
  const hello = () => {
    console.log("enter");
  };

  return (
    <div className="App">
      <Form onSubmit={hello}>
        <Form.Item>
          <Button type="primary" htmlType="submit">
            Apply
          </Button>
        </Form.Item>
      </Form>
    </div>
  );
}

I am trying to invoke the function when user press the apply button, but it nothing is showing. Where am I doing it wrong??

This is my codesandbox

3
  • 1
    I think there is no submit prop in antd form, you can use onFinish prop Commented Oct 14, 2021 at 7:14
  • Before posting any question, please go through documentation. Commented Oct 14, 2021 at 7:16
  • 1
    ant.design/components/form/#Form - see onFinish Commented Oct 14, 2021 at 7:17

2 Answers 2

1

The issue is onSubmit according to antd document it should be onFinish

Here is the code:

import "./styles.css";
import { Form, Button } from "antd";
export default function App() {
  const hello = () => {
    console.log("enter");
  };

  return (
    <div className="App">
      <Form onFinish={hello}>
        <Form.Item>
          <Button type="primary" htmlType="submit">
            Apply
          </Button>
        </Form.Item>
      </Form>
    </div>
  );
}
Sign up to request clarification or add additional context in comments.

Comments

0

According to the antd documentation, Forms onFinish is the identifier for submitting callback rather than onSubmit. So you can use:

<Form onFinish={hello}>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.