React (0.13) using the Componentdidmount method to set a timer

Source: Internet
Author: User

varHello =React.createclass ({getinitialstate:function(){                        return{opacity:1.0}; }, Componentdidmount:function(){                         This. Timer = SetInterval (function(){                            varOpacity = This. state.opacity; Opacity-= 0.1; if(Opacity < 0.1) {opacity= 1.0                            }                                                         This. SetState ({opacity:opacity}); }.bind ( This), 100); }, Render:function(){                        return (                            <div style={{opacity: This.state.opacity}}>Hello { This. Props.name}</div>                        );                        }                }); //adding components to EReact.render ()            ); </script> </body>

The life cycle of a component

The life cycle of a component is divided into three states:

    • Mounting: The real DOM is inserted

    • Updating: is being re-rendered

    • Unmounting: The real DOM has been removed

React provides two processing functions for each State, the will function is called before it enters the state, and the DID function is called after it enters the state, with three states totaling five processing functions.

    • Componentwillmount ()

    • Componentdidmount ()

    • Componentwillupdate (Object Nextprops, Object nextstate)

    • Componentdidupdate (Object Prevprops, Object prevstate)

    • Componentwillunmount ()

In addition, the REACT provides two special state processing functions.

    • Componentwillreceiveprops (Object Nextprops): Called when a loaded component receives a new parameter

    • Shouldcomponentupdate (Object Nextprops, Object nextstate): Called when the component determines whether to re-render

React (0.13) using the Componentdidmount method to set a timer

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