DEV Community

Hardik Kanajariya
Hardik Kanajariya

Posted on

Building Your First React Application: A Step-by-Step Tutorial

React is a popular JavaScript library for building user interfaces. In this tutorial, we'll create your first React application from scratch.

Prerequisites

  • Basic JavaScript knowledge
  • Node.js installed on your computer
  • A code editor (VS Code recommended)

Getting Started

Step 1: Create React App

npx create-react-app my-first-app
cd my-first-app
npm start
Enter fullscreen mode Exit fullscreen mode

Step 2: Understanding the Structure

  • src/ - Your application code
  • public/ - Static files
  • package.json - Dependencies

Step 3: Create Your First Component

function Welcome() {
  return <h1>Hello, React!</h1>;
}
Enter fullscreen mode Exit fullscreen mode

Step 4: Add State

import { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);
  return (
    <button onClick={() => setCount(count + 1)}>
      Count: {count}
    </button>
  );
}
Enter fullscreen mode Exit fullscreen mode

Conclusion

Congratulations! You've built your first React app. Keep experimenting and building!

Top comments (0)