View on GitHub

reading-notes

React and Forms

Controlled Component

The textarea Tag

The select Tag

Overall, this makes it so that < input type=”text”>, < textarea>, and < select> all work very similarly - they all accept a value attribute that you can use to implement a controlled component.


Note :You can pass an array into the value attribute, allowing you to select multiple options in a select tag:

<select multiple={true} value={['B', 'C']}>

The file input Tag

Handling Multiple Inputs

Controlled Input Null Value

The Conditional (Ternary) Operator

typical if statement:

if ( condition ) {
 value if true;
  } else {
  value if false;
 }

ternary operator:

condition ? value if true : value if false

1- The condition is what you’re actually testing. The result of your condition should be true or false or at least coerce to either boolean value.

2- A ? separates our conditional from our true value. Anything between the ? and the : is what is executed if the condition evaluates to true.

3- Finally a : colon. If your condition evaluates to false, any code after the colon is executed.

example :

typical if statement:

  if(x===y){
   console.log(true);
   } else {
   console.log(false);
   }

ternary operator:

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


Refrence :