React Hello World App using Functional Component
π INTRODUCTION
React is one of the most popular JavaScript libraries used for building modern web applications.
In this program, we will learn how to:
- Create a basic React application
- Use a functional component
- Display “Hello, World!” on the screen
π This is the first and most important React program for beginners.
π PROBLEM STATEMENT
π Write a program to display “Hello, World!” using a functional component in React.
π‘ CONCEPTS USED
- React Functional Components
- JSX (JavaScript XML)
- Component Rendering
βοΈ PREREQUISITES
Make sure you have:
- Node.js installed
- npm or yarn installed
π§ LOGIC EXPLANATION
- Create a React app
- Define a functional component
- Return JSX
- Render it on the screen
π STEP 1: CREATE REACT APP
Open terminal and run:
npx create-react-app hello-app
cd hello-app
npm start
π» STEP 2: WRITE CODE
Open src/App.js and replace with:
function App() {
return (
<div>
<h1>Hello, World!</h1>
</div>
);
}
export default App;
π₯οΈ OUTPUT
π When you run the app, you will see:
Hello, World!
π STEP-BY-STEP EXPLANATION
function App()β defines a functional componentreturn()β returns JSX<h1>β HTML element inside JSXexport default Appβ makes component usable
β‘ USING ARROW FUNCTION (MODERN WAY)
const App = () => {
return (
<div>
<h1>Hello, World!</h1>
</div>
);
};
export default App;
π― WHY FUNCTIONAL COMPONENTS?
- Simple and easy to write
- Less code compared to class components
- Used with React Hooks (
useState,useEffect) - Industry standard
π REAL-WORLD USE CASE
- Building UI components
- Creating reusable elements
- Designing full React applications
β VIVA QUESTIONS (IMPORTANT)
Q1. What is a functional component in React?
π A JavaScript function that returns JSX.
Q2. What is JSX?
π JSX is a syntax that allows writing HTML inside JavaScript.
Q3. Difference between functional and class components?
π Functional components are simpler and use hooks, while class components use lifecycle methods.
Q4. What is export default?
π It allows the component to be imported in other files.
Q5. Can we use arrow functions in React components?
π Yes, it is the modern and preferred way.
π RELATED POSTS
π MCA 168 Full Stack Development Lab Programs List
π Arrow Function β Program 1
π Template Literals β Program 2
π Destructuring Assignment β Program 3
π Spread Operator β Program 4
π CONCLUSION
This is the foundation of React development. Once you understand functional components, you can easily move to advanced topics like state management and hooks.
π Practice creating multiple components to strengthen your understanding.
Further Reading
How to Master Full Stack Development?
Spring Framework Practice Problems and Their Solutions
From Google to the World: The Story of Go Programming Language
Why Go? Understanding the Advantages of this Emerging Language
Creating and Executing Simple Programs in Go
20+ Interview Questions on Go Programming Language
100+ MCQs On Java Architecture
- Angular
- ASP.NET
- C
- C#
- C++
- CSS
- Dot Net Framework
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- PHP
- Power Bi
- Python
- Scratch 3.0
- TypeScript
- VB.NET
