React Components

Wednesday, March 18, 2020

React Components


React components are independent and reusable bits of code. They are similar to JavaScript functions as they both serve the same purpose, but react components work in isolation and returns HTML through a render function.




Reacts lets you define 2 types of components.

  1. Class - based components.
  2. Functional components
With these components it is important have an understanding as to which kind of component can do what , what their history is and what the future holds for them.


Class-Based Components Functional Components
Class A extends Component const A = props => {...}
Access to state With react hooks able to access state
Ability to use life cycle hooks No support for life cycle hooks
Ability State and Props via "this" Access props via "props"
Ability to use life cycle hooks No support for life cycle hooks



Important :  Use class-based components if you need to manage state or access the Life cycle Hooks and if you cannot or do not want to use React Hooks.




0 comments :

Post a Comment