Reading-notes

React Docs - Forms

What is a ‘Controlled Component’?

A controlled component is a component that renders form elements and controls them by keeping the form data in the component’s state.

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.

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 :

How do we target what the user is entering if we have an event handler on an input field?

The Conditional (Ternary) Operator Explained:

Why would we use a ternary operator?

Shorten your if statements into one line of code with the conditional operator , most clear and more simplefy with out making problem .

Rewrite the following statement using a ternary statement:

x=y ? console.log(true) : console.log(false);