Life cycle of react

constructor(props) {
        super(props);
        this.state = {
            form:this.props.form
        };
    }
    
    

{this.props.form.name}

Why do I initialize the child component here to get the parent component data through pros
when my child component calls the parent component event to change the data
name can also be changed initialization method is not executed only once

when I have two components An and B A components call parent component method parent component data change
trigger B component data update operation, A component passes data as above
B component can not update data through componentWillReceiveProps () method

 

class ComModal extends React.Component{
        constructor(props) {
            super(props);
            this.state = {
              form:{
                  
              },
              show:false
              
            };
        }
        showChange(){
            that.setState({
                show:true
            })
        }
        
        render(){
            return(
                <div>
                    <A cbclick={e=>that.showChange()}/>
                    <B show={that.state.show}/>
                </div>
            )
        }
    }
    
  A
  class A extends React.Component{
      showChange()
  }
  B
   class B extends React.Component{
     constructor(props) {
        super(props);
        this.state = {
           show:this.props.show    //Ashow render
        };
    }
    componentWillReceiveProps(nextProps){
        
    }
   
      render(){
          return (
              

{that.state.show?"":""}

) } }
Mar.02,2021

the parent component transfers data to the child component through props. If the props changes, the data obtained by the child component will also change. There is a function with property change that can detect


.

React has three phases: mounting, updating, and uninstalling.

The main declaration periods of

mount are:

  • constructor
  • render
  • componentDidMount

where constructor binds the props passed by the parent component to the this of the child component.

if the callback function passed by the parent component is called to change the data, the props passed by the parent component will change
then trigger the update phase of the child component:

  • componentWillReceiveProps
  • shouldComponentUpdate
  • render
  • componentDidUpdate.
when my child component calls the parent component event to change the data, the value name of the child component can also be changed

the in this sentence I said to you has changed , and it is understood that the data displayed on the page has changed. What controls the change in the display of the page is the render life cycle. As you can see above, render will be triggered regardless of whether it is mounted or updated.


  

can't you tag react ?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5f4ac-65e30.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5f4ac-65e30.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?