I decided to include form elements in a rather interesting way to show the power of React.
The best examples can be seen in the calls to the Text Input and Radios components.
is a fantastic user interface primarily library because the user’s view updates automatically when a state changes.
This ability to show changes to the user quickly also makes it a good fit for user-facing form errors.
In this case, we use it with the second Text Input component and return true, because we need the validate prop function to exist, but we don’t actually want to validate the second field.
The component itself doesn’t care what type of validation is going on.Since this is a form, we are also including jquery, which will make form submission much easier.We don’t actually make much use of it in the code, other than an example submission function.Just be sure to put “text/babel” in your script type so you can make use of JSX in your code.Now let’s dig into the code: Setting up for form submission The React DOM.render call at the bottom of the code is the first call that starts the app.The handle Submit method shows how you would pass the variable to the parent element when the form is submitted.What we want to focus on, though, is the validation functions and component calls.It simply calls validate, and the parent component takes care of which validation function is being called.I’ve also included a common Validate function as an example of how you could do some basic validation on all form fields.React allows you to easily display errors as the form is being filled so the user doesn’t have to fill in the entire form, press the submit button, then try to figure out what they got wrong.This does not mean React can be used to make a form secure.