Friday, 28 January 2022

Chapter3-Components

  React component can be created in two different ways

A) Using Functions: 

function Hello() { 

return 'Hello'

 } 

B) Using Class: 

class Hello extends React.Component { 

render() {

return (

<div>

<p>Hello World</p>

</div>

)

}

}

export default Hello;

Class components supports state management out of the box whereas function components does not support state management. But, React provides a hook, useState() for the function components to maintain its state.

Class component have a life cycle and access to each life cycle events through dedicated callback apis. Function component does not have life cycle. Again, React provides a hook, useEffect() for the function component to access different stages of the component.


PostedBy: pankaj_bhakre

No comments:

Post a Comment