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);
- Getdefaultprops//Create a build props
- Getinitalstate//Instantiation status
- Componentwillmount//before mounting
- Componentdidmount//Mount
- Componentwillreceiveprops//When the property is changed
- Shouldcomponentupdate//Whether with the new
- Componentwillupdate//Pre-update
- Componentdidupdate//After update
- 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