Beginner⏱️ 6 min📘 Topic 1 of 13

⚛️ Introduction to React — What It Is & Why Everyone Uses It

Learn what React is, why it became the most popular UI library, and how the virtual DOM works. Beginner-friendly intro with code examples and real interview questions.

React is a JavaScript library for building user interfaces. Created at Facebook (now Meta) in 2013, it powers Instagram, Netflix, Airbnb, WhatsApp Web, and most of the modern web.

🧠 The big idea

Instead of telling the browser how to update the DOM (imperative), you describe what the UI should look like for a given state (declarative). React figures out the cheapest way to make the real DOM match.

⚡ The Virtual DOM

React keeps a lightweight copy of the DOM in memory. When state changes, it builds a new virtual tree, diffs it against the old one, and only touches the real DOM where something changed. Fast and predictable.

🧩 Components everywhere

Everything is a component — a function that returns JSX. Components compose: small ones build bigger ones, like LEGO bricks.

function Button({ label }) {
  return <button>{label}</button>;
}

💡 React is a library, not a framework

It ships only the view layer. Routing, data fetching, forms — pick your own. That flexibility is both its strength and its learning curve.

👉 Try this yourself: open StackBlitz, pick "React", and edit App.jsx. See your changes live in seconds.

💻 Code Examples

The smallest React component

function Hello() {
  return <h1>Hello, React!</h1>;
}
Output:
Renders an <h1> on the page.

Composing components

function Avatar() { return <img src="/me.png" />; }
function Name() { return <span>Sam</span>; }
function Profile() {
  return (
    <div>
      <Avatar />
      <Name />
    </div>
  );
}
Output:
Renders avatar + name inside a div.

⚠️ Common Mistakes

  • Thinking React is a framework like Angular — it's only the UI layer.
  • Believing the virtual DOM is always faster — it's the diffing+batching that helps, not the copy itself.
  • Avoiding React because 'JSX looks like HTML in JS' — it compiles to plain function calls.

🎯 Interview Questions

Real questions asked at top product and service-based companies.

Q1.What is React?Beginner
React is an open-source JavaScript library for building user interfaces with reusable, component-based, declarative code. It uses a virtual DOM to efficiently update the real DOM when state changes.
Q2.Is React a library or a framework?Beginner
A library. It only handles the view layer. You add routing, data fetching, forms and state management separately. Frameworks like Angular bundle all of that in.
Q3.What is the virtual DOM and how does it work?Intermediate
It's an in-memory representation of the UI. When state changes, React builds a new virtual tree, diffs it against the previous one (reconciliation), and applies only the minimum number of real DOM mutations needed. This batching + minimization is what makes it fast.
Q4.What problem does React solve?Intermediate
It tames the complexity of keeping the DOM in sync with application state. Instead of manually mutating the DOM as data changes, you describe UI as a function of state and React handles the synchronization.
Q5.Why is React so popular?Beginner
Component model, large ecosystem, strong community, backed by Meta, gentle learning curve for the basics, and excellent dev tooling (Fast Refresh, React DevTools).

🧠 Quick Summary

  • React = declarative UI library, not a full framework.
  • Everything is a component — a function returning JSX.
  • Virtual DOM + diffing makes updates fast and predictable.
  • You compose small components into bigger ones.
  • Used by Meta, Netflix, Airbnb, and most modern web apps.