DEV Community

SATHISHKUMAR R
SATHISHKUMAR R

Posted on

What is a Component in React?

A component is a reusable piece of UI (User Interface) in a React application.

  1. Types of Components:

React commonly uses two types of components in learning materials.

  1. Functional Component: A JavaScript function that returns JSX. This is the standard approach in modern React.

function Welcome() {
return

Welcome to React!

;
}

export default Welcome;

  1. Class Component: A component written using a JavaScript class. You may see these in older React projects.

import { Component } from "react";

class Welcome extends Component {
render() {
return

Welcome to React!

;
}
}

export default Welcome;

  1. How to use a Component: Create two files.

Welcome.jsx

function Welcome() {
return

Hello Sathish!

;
}

export default Welcome;

App.jsx

import Welcome from "./Welcome";

function App() {
return (



Learn React step by step.



);
}

export default App;

Browser output:

Hello Sathish!

Top comments (0)