Declare a state variable named searchQuery to be held by the component before creating an event handler for the input element.
Next, construct a handleInputChanged method:
Attach the event handler function to the input element's onChange attribute:
As it comes to handling forms, it's all about how you manage the data when it changes or is submitted. In HTML, form data is normally handled via the Document Object Model (DOM). Form data is often handled by components in React. All data is kept in the component state when it is handled by the components.
What we need to do now is make it possible to validate form data and display error warnings when necessary. We may do the validation every time we render because React renders the component as soon as the state changes. That also implies there's no need to keep track of any faults.
In React, there are two sorts of form input. We have two types of input: uncontrolled and controlled. In that they remember what you typed, the uncontrolled inputs are similar to standard HTML form inputs. To get the form values, we'll utilise ref.