A controlled component is a component that renders form elements and controls them by keeping the form data in the component’s state.
The second:update the state whil with users responses ..we have to read the value from the input element whenever we want it. This means we can’t provide instant validation on the field as the user types, nor can we do things like enforce a custom input format, conditionally show or hide form elements, or disable/enable the submit button. Fortunately, there’s a more sophisticated way to handle inputs in React.
An input is said to be “controlled” when React is responsible for maintaining and setting its state. The state is kept in sync with the input’s value, meaning that changing the input will update the state, and updating the state will change the input. and for some reson :
instant input validation: we can give the user instant feedback without having to wait for them to submit the form (e.g. if their password is not complex enough).
conditionally disable form submission: we can enable the submit button after certain criteria are met (e.g. the user consented to the terms and conditions)
The event also applies to elements with contenteditable enabled, and to any element when designMode is turned on. In the case of contenteditable and designMode, the event target is the editing host. If these properties apply to multiple elements, the editing host is the nearest ancestor element whose parent isn’t editable.
For elements with type=checkbox or type=radio, the input event should fire whenever a user toggles the control, per the HTML5 specification. However, historically this has not always been the case. Check compatibility, or use the change event instead for elements of these types.
Shorten your if statements into one line of code with the conditional operator , most clear and more simplefy with out making problem .
x=y ? console.log(true) : console.log(false);