React website Learning

Source: Internet
Author: User

A stateful component

In addition to accepting input data (through this.props ), the component can also maintain internal state data (through this.state ). When the state data of a component changes, the markup that is displayed is called back to render() update.

First look at the structure, here is the hook function

hook function:<br>
The first is a system mechanism for replacing interrupts under a DOS system, provided under Windows systems;<br>
Now it is a generic, after the specific system event hook, once the hook event occurs, the event to hook the program, you will receive a system notification. This is the program that responds to the first time the event is made.

//mounting means that React components is generated by render parsing a process that generates the corresponding DOM node and is inserted into the DOM node of the browser and inserted into the browser's DOM structure//order of execution SeevarTimer =React.createclass ({//Initialize stateGetinitialstate:function() {    return{secondselapsed:0}; }, tick:function() {  //call SetState to re-assign a value of secondselapsed, which will be re-render after the call     This. SetState ({secondselapsed: This. state.secondselapsed + 1}); },  //React components life cycle is called after renderComponentdidmount:function() {
Timer Update This. Interval = SetInterval ( This. Tick, 1000); }, //react the components lifecycle is called when the control is destroyedComponentwillunmount:function() {
Clears the current timer clearinterval ( This. Interval); }, Render:function() { return ( //output current secondselapsed value<div>seconds Elapsed: { This.state.secondselapsed}</div> ); }});//Mountnode, bound to the specified ID, generally so write document.getElementById (' app ')React.render (<timer/>, Mountnode);

React website Learning

Related Article

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: 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.