Handling form submission

We already have a submit button in the Form component that submits the form. We aren't handling the form submission yet though. Let's handle form submission, which includes a call to a function passed in by the consumer:

  1. In Form.tsx, let's import the FormEvent type from React:
import { FC, useState, createContext, FormEvent } from 'react';
  1. Let's add an event listener for the submit event in the Form component JSX:
<form noValidate={true} onSubmit={handleSubmit}>  ...</form>

When the submit button is clicked on the form, the submit event will be triggered and a function called handleSubmit will be invoked.

  1. Let's start to implement the handleSubmit function just beneath the validate function:
const handleSubmit ...

Get ASP.NET Core 3 and React now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.