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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjroyN4bIII8J9k2v5_dts2wnyIbrEynHAlz_tmicdUZN0AOkHLorgeS_47TlX8XvjRRmMHWkX1eEbp2H0i4V3t_Bs0g1HLa6RruYlUKEPHElAxS1zKim3OqgTwxR8wE6Sbsw51OfTP2qc/d/React-Component_01.jpg)
Reacts lets you define 2 types of components.
- Class - based components.
- 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