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