Reducing boilerplate code with React Hook Form
In this section, we are going to use a popular forms library called React Hook Form. This library reduces the amount of code we need to write when implementing forms. Once we have installed React Hook Form, we will refactor the search form we created in the previous section. We will then use React Hook Form to implement forms for asking a question and answering a question.
Installing React Hook Form
Let's install React Hook Form by entering the following command into the Terminal:
> npm install react-hook-form
After a few seconds, React Hook Form will be installed.
The react-hook-form
package includes TypeScript types, so these aren't in a separate package that we need to install.
Next, we will start to use React Hook Form for the search form in the Header
component.
Refactoring the Header component to use React Hook Form
We are going to use React Hook Form to reduce the amount of code in the Header...