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.
A React component is a JavaScript function or class that returns JSX.
Functional components are simple JavaScript functions.
Easy to write and test
Support Hooks
Preferred in modern React
Class components use ES6 classes.
More complex
Mostly replaced by functional components
Components can be used like HTML tags.
Component names must start with a capital letter
File names usually match component names (e.g., Header.jsx)
Use it multiple times:
Components can contain other components.
A component must return one parent element
Use a fragment (<> </>) if needed
Importing:
Components are reusable UI blocks
Functional components are standard
Components can be nested
Each component returns JSX
Take quizzes related to this topic and see where you stand!
Start Quiz Now