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