reading-notes

View project on GitHub

Class4

Return to home page.

React Forms

  • What is a ‘Controlled Component’?

An input form element whose value is controlled by React.

  • 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.

we should update the state with their responses as soon as they enter them, because it makes it possible to perform continuous validation on inputs as the user types.

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

Since the value attribute is set on our form element, the displayed value will always be this.state.value.

The Conditional (Ternary) Operator

  • Why would we use a ternary operator?

We use the ternary operator to simplify our if-else statements that are used to assign values to variables.

  • Rewrite the following statement using a ternary statement:

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