React----talking about Reactjs

Source: Internet
Author: User

1. Hello React Simple component building.

var helloreact = React.createclass ({

Render:function () {

Return (

<div>hello react!</div>

)

}

});

Reactdom.render (

Document.queryselector (' body ');

)

2, React life cycle (initialization, update and destruction);

    1. Getdefaultprops//Create a build props
    2. Getinitalstate//Instantiation status
    3. Componentwillmount//before mounting
    4. Componentdidmount//Mount
    5. Componentwillreceiveprops//When the property is changed
    6. Shouldcomponentupdate//Whether with the new
    7. Componentwillupdate//Pre-update
    8. Componentdidupdate//After update
    9. Componentwillunmount//Before destruction

3, React data initialization, and React provides us with two ways to pass data to the component, namely props and state.

Props Delivery

var helloreact = React.createclass ({

Getdefaultprops:function () {

return {

Data: ""

}

},

Render:function () {

Return (

<div>

{This.props.data}

</div>

)

}

})

Reactdom.render (

Document.queryselector ("Body")

)

State is not passed externally

var helloreact = React.createclass ({

Getinitialstate:function () {return data: ""},

Componentdidmount:function () {this.requestdata ();},

Requestdata:function () {
$.ajax ({

URL: "Http://www.baidu.com",

Data: {},

Success:function (data) {

This.setstate ({

Data:data

})

}

}.bind (this));

},

Render:function () {

Return (

<div>

{This.state.data}

</div>

)

}

});

React.render (

Document.queryselector ("body");

)

React----talking about Reactjs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.