Component

What is a Component?

A component is an independent, reusable code block which divides the UI into smaller pieces.

React has two types of components:

1-functional Component
2-class Component

Functional Components

A functional component is basically a JavaScript/ES6 function that returns a React element (JSX).

a Functional Component in React:

–>is a JavaScript/ES6 function
–>must return a React element (JSX)
–>always starts with a capital letter (naming convention)
–>takes props as a parameter if necessary

What are Class Components?

Class components are ES6 classes that must have an additional render( ) method for returning JSX.

A Class Component:

–>is an ES6 class, will be a component once it β€˜extends’ a React component.
–>takes Props (in the constructor) if needed
–>must have a render( ) method for returning JSX