read 4
React and Forms
What is a ‘Controlled Component’?
A Controlled Component is one that takes its current value through props and notifies changes through callbacks like onChange . A parent component “controls” it by handling the callback and managing its own state and passing the new values as props to the controlled component.
Should we wait to store the users responses from the form into state when they submit the form OR should we update the state with their responses as soon as they enter them? Why.
I feel when you are updated the state of react is more better to can be controlled component for React, in my opinion It is more effiecient than waiting to store user state.
How do we target what the user is entering if we have an event handler on an input field?
more useful users interaction with an input field you can use attributes to target the specific element, then you can use the event handler to handle that target event.
The Conditional (Ternary) Operator Explained
Why would we use a ternary operator?
Use the ternary operator to simplify your if-else statements that are used to assign values to variables. The ternary operator is commonly used when assigning post data or validating forms.
Rewrite the following statement using a ternary statement:
if (x == y){
return true;
}
else{
return false;
}