In this tutorial 👩🏻💻 🔥 , we are going to learn about functional components in react.
First, let us know about components.
❓. What is a component?
A component is a core building block of react.
There are two types of components:
let us take an example for each.
Now we will dive into Functional components👩🏻💻.
> const n=<Component name="Ana" />;
Inside a functional component, we are passing props as an argument of the function.
A functional component is an ES6 function.
❓ When do we use functional components?
1)when it receives prop and renders something.
2)when it doesn't have any state.
❓ Why functional components?
Ans: A functional component is written shorter and simpler. It doesn't use THIS unlike in class component.
Functional component holds state using hooks. (react 16.8)
Let's us code now,
try these examples on a code editor.