[React Fundamentals] Component lifecycle-updating

Source: Internet
Author: User

The React component lifecycle would allow you to update the your components at runtime. This lesson would explore how to does that.

Import React from 'react'; import Reactdom from 'React-dom'; exportdefault classApp extends React.component {constructor () {super ();  This. State ={increasing:false}} update () {Reactdom.render (<app val={ This. props.val+1}/>, document.getElementById ('app')); } componentwillreceiveprops (nextprops) {//invoked when a component is receiving new props. This method isn't called for the initial render.         This. SetState ({increasing:nextProps.val> This. Props.val}) } shouldcomponentupdate (Nextprops, nextstate) {//Control Whether the component should re-render        returnNextprops.val%5===0;//Update DOM every 5 clicks} render () {Console.log ( This. state.increasing); return (            <div> <button onclick={ This. Update.bind ( This)}>{ This.props.val}</button> </div>)} componentdidupdate (Prevprops, prevstate) {//After DOM updateConsole.log ("Prevprops", Prevprops); }}app.defaultprops={val:0}

[React Fundamentals] Component lifecycle-updating

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.