React- form processing

The concept of a controlled components

  First of all html in each form element has its own properties, manage their own, but want to react to each form attribute value to the state for processing and unified management, this time to put the two were combined

  The value is the value of the controlled components to form elements of state management

 

Second, based on the use of controlled components

  1. Control form element source

  2. Changes in the value of the control element form

React from Import 'REACT'  

Export default class React.Component the extends the App {
   // 1. Control form element source 
  State = { 
    value: '. 1' 
  } 
  
  // 2. Control form element changes 
  handle = E => {
     the this .setState ({ 
      value: e.target.value 
    }) 
  } 

  the render () { 
    return (
       <div> 
        <INPUT value = { the this .state.value the onChange = {} the this .handle} /> 
      </ div>     ) 
  } 
}

 

Guess you like

Origin www.cnblogs.com/xiaowzi/p/12353155.html