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:
- In Form.tsx, let's import the FormEvent type from React:
import { FC, useState, createContext, FormEvent } from 'react';
- 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.
- Let's start to implement the handleSubmit function just beneath the validate function:
const handleSubmit ...