A component is a reusable piece of UI (User Interface) in a React application.
- Types of Components:
React commonly uses two types of components in learning materials.
- 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;
- 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;
- 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)