My reading journal for Code Fellows.
A controlled component is a form that is configured so that the component that renders it also controls what happens in it following any user input.
As long as you can constantly keep the state up to date with the user input by using something like onChange, then I think you should update state upon data entry. This gives you the option to use that state data somewhere else in the same form either before or on submission of the form. This would be impossible if you hadn’t already stored the data in state upon entry.
You can target the user input using event.target.value
.
The ternary operator allows you to shorten an if statement to one simple line of code.
if(x===y){
console.log(true);
} else {
console.log(false);
}
x===y ? console.log(true) : console.log(false)
I want to understand controlled components better. It sounds like using controlled components allows you to do a lot of cool stuff in React and I look forward to learning how to properly implement them in my code.