How to create a component in react js

How to create a component in react js

In this article, we will explain to you how to create a component in react js. Component means a specific part of code that is reuse in your code. there are two types of components. Function component and Class component. so we will know about the Function component and Class component.

so you can see the following example to create a component in react js.

Create a Function Component

The Function component is a simple component because we can not create our own state and props. it also returns only render, so it’s known as a stateless component.

Example

Create a Class Component

The Class component is the same as the Function component but we can declare a class and extends the react component (React.Component), the class’s name must be uppercase.

we can create our own state and props. it’s known as a stateful component. we can easily add one component to another component.

Example

Related Posts
Please follow and like us: