React Components Basics
⏱ Estimated reading time: 2 min
Components are the core building blocks of a React application. A component represents a part of the user interface and can be reused throughout the app.
What is a Component?
A React component is a JavaScript function or class that returns JSX.
Types of Components
1. Functional Components (Recommended)
Functional components are simple JavaScript functions.
-
Easy to write and test
-
Support Hooks
-
Preferred in modern React
2. Class Components (Older)
Class components use ES6 classes.
-
More complex
-
Mostly replaced by functional components
Using Components
Components can be used like HTML tags.
Component Naming Rules
-
Component names must start with a capital letter
-
File names usually match component names (e.g.,
Header.jsx)
Reusable Components
Use it multiple times:
Nesting Components
Components can contain other components.
Returning JSX
-
A component must return one parent element
-
Use a fragment (
<> </>) if needed
Exporting Components
Importing:
Key Points
-
Components are reusable UI blocks
-
Functional components are standard
-
Components can be nested
-
Each component returns JSX
Register Now
Share this Post
← Back to Tutorials