#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
React Fundamentals

Creating Your First React Application

Creating your first React application means generating a project with a build tool that sets up React, a fast development server and a production build command for you. Today the usual choice for learning is Vite, which creates a working React app in seconds. Older tutorials use Create React App, which the React team has since deprecated for new projects.

Before you start

You need Node.js installed, which also gives you npm, the package manager. Check both from a terminal with node -v and npm -v. A code editor such as VS Code and a modern browser complete the setup.

Generating the project

# Create a new React project called my-first-app
npm create vite@latest my-first-app -- --template react

# Move into it and install dependencies
cd my-first-app
npm install

# Start the development server
npm run dev
#   Local:   http://localhost:5173/

# Later: create an optimised build in the dist/ folder
npm run build

The extra -- passes the template option through npm to the Vite tool. Choose react-ts instead of react if you want TypeScript.

What you get

Open the project folder in your editor and you will find a small set of files:

  • index.html sits at the project root and contains a single div with the id "root", where React draws the app.
  • src/main.jsx is the entry point. It finds that div and renders the App component into it.
  • src/App.jsx is your first component, showing a counter button.
  • package.json lists dependencies and the dev, build and preview scripts.
  • node_modules holds installed packages; it is never edited by hand and is excluded from version control.

Making your first change

With the dev server running, replace the contents of App.jsx with a component of your own and save. The browser updates instantly without a full reload, thanks to hot module replacement, and component state is often preserved.

// src/App.jsx
import { useState } from "react";

function App() {
  const [name, setName] = useState("");

  return (
    <main>
      <h2>Hello{name ? `, ${name}` : ""}!</h2>
      <input
        placeholder="Type your name"
        value={name}
        onChange={(e) => setName(e.target.value)}
      />
    </main>
  );
}

export default App;

Problems first-timers run into

"npm: command not found" or "'npm' is not recognized" means Node.js is not installed, or the terminal was opened before installation finished. Reopen the terminal after installing.

Running npm run dev from the wrong folder gives "Missing script: dev" or "Could not read package.json". Always cd into the project folder first; the folder containing package.json is the one that matters.

Some learners also try to open index.html by double-clicking it. That shows a blank page, because the JSX has to be processed by the dev server. Always use the URL the server prints.

Finally, if port 5173 is already in use, Vite picks the next free port automatically. Read the terminal output for the exact address instead of assuming.

Stopping and restarting

Press Ctrl + C in the terminal to stop the dev server. Run npm run dev again whenever you return to the project. You only need npm install again when dependencies change or after cloning the project on another machine.

Takeaway: install Node.js, generate a project with npm create vite@latest, run npm install and npm run dev inside the project folder, and edit src/App.jsx to see changes live.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course