Daily Reading 4
React and Forms
What is a ‘Controlled Component’?
Some components, due to their fundamental nature, keeps their own states. The HTML form function is a good example, because it holds data and keeps it, independent of react entering the picture. A controlled component is when you hook react into the state, to make react be the sole influencer of it’s state as a method of code cleanup.
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.
React has a call called handleChange that fires each time any keystroke is made. For this reason it’s a good idea to update absolutely everything instantly, because react is capable of it, and it keeps things consistent.
How do we target what the user is entering if we have an event handler on an input field?
Use of the
The Conditional (Ternary) Operator Explained
Why would we use a ternary operator?
It compresses an if statement from an average of 5 lines, to a single line, massively simplifying both the speed and readability of your code.
Rewrite the following statement using a ternary statement:
{
if(x===y){
console.log(true);
} else {
console.log(false);
}
}
{
x===y ? console.log(true) : console.log(false);
}