Lang
Blog

What are Component Lifecycle Methods in React JS??

Like us all, React components also take birth, grow, and die!

ByPayal Mittal
December 7th . 5 min read
What are Component Lifecycle Methods in React JS?
constructor(props) {
  super(props);
this.state = { count: 0 };
  this.handleClick = this.handleClick.bind(this);
  console.log("Constructor!");
}
class MyComponent extends React.Component {
   render() {
//return string
    return "Hello!!"
//return null value in case you don't want to render anything
    return null
//return fragments   
    return <React.Fragment>
            <div>Hello</div>
            <div>Friends</div>
      </React.Fragment>
//return arrays        
      return [
          <div key="1">Hello</div>, 
          <div key="2">World</div>
      ];
 }
}
getSnapshotBeforeUpdate(prevProps, prevState) {
return null;
}
Share:
0
+0