#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

Introduction to React

React is a JavaScript library for building user interfaces out of components. Instead of writing step-by-step instructions to change the page, such as "find this element and update its text", you describe what the screen should look like for the current data, and React updates the browser's DOM to match. It is used for anything from a small interactive widget to a complete single-page application.

The ideas React is built on

  • Components. The interface is split into reusable pieces, like Navbar, ProductCard or LoginForm. Each is a JavaScript function that returns markup.
  • Declarative rendering. You write what the UI should be for a given state. When the state changes, React works out the minimal DOM changes needed.
  • JSX. An HTML-like syntax inside JavaScript that makes component output easy to read. A build tool converts it into regular function calls.
  • One-way data flow. Data moves from parent components to children through props. This makes it easier to trace where a value comes from.
  • State. Each component can hold data that changes over time, using hooks like useState, and React re-renders it when that data changes.

Plain DOM code versus a React component

// Plain JavaScript: you manage every update yourself
let count = 0;
const button = document.querySelector('#like');
button.addEventListener('click', () => {
  count++;
  button.textContent = `Likes: ${count}`;
});

// React: describe the UI for the current count
import { useState } from 'react';

function LikeButton() {
  const [count, setCount] = useState(0);
  return (
    <button onClick={() => setCount(count + 1)}>
      Likes: {count}
    </button>
  );
}

export default function App() {
  return (
    <main>
      <h1>My posts</h1>
      <LikeButton />
      <LikeButton />
    </main>
  );
}

In the plain version, you must remember to update the text every time count changes. In React, the text is derived from state, so it can never fall out of sync. Each LikeButton also keeps its own count, so reusing it twice just works.

What React does not include

React focuses on the view layer. It does not come with a router, a data-fetching library, form tools or styling rules. You add those as needed, for example React Router for pages, or use a framework built on React, such as Next.js, which bundles routing and server rendering. This keeps React small but means a real project involves choosing a few extra packages.

Starting a project

The quickest modern way to try React locally is with Vite:

  1. Run npm create vite@latest my-app -- --template react.
  2. Move into the folder and run npm install.
  3. Start the dev server with npm run dev and open the address it prints.

Edit src/App.jsx and the browser updates instantly. Older tutorials use Create React App, which is no longer the recommended starting point.

A misconception to drop early

Many beginners keep using document.querySelector and change the DOM directly inside React components, as they did with plain JavaScript or jQuery. This fights React: the next re-render may overwrite the manual change, or React's idea of the page drifts from what is shown. Store changing values in state and let the JSX reflect them. When you genuinely need a DOM element, for example to focus an input, use a ref.

A second misconception is that React is a full framework that decides your whole architecture. It is a library for the UI; the rest of the structure is up to you.

Where React fits

React lets you build interfaces from components that turn state into markup, with JSX for readable output and hooks for changing data. It handles the view and leaves routing, data and styling choices to you. The next lesson looks at how React came about and why its approach spread so widely.

Ready to master real-world web development?

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

Explore Course