juniorReact

What is React?

Updated May 16, 2026

Short answer

What is React?

Meta React is a JavaScript library used for building user interfaces (UI), especially for single-page applications (SPAs).

It helps developers create fast, reusable, and interactive web applications by breaking the UI into small reusable pieces called components.

React was created by Jordan Walke at Meta.

Example:

JSX
function App() {
return <h1>Hello World</h1>;
}

This code creates a UI component that displays:

TEXT
Hello World

---

Deep explanation

Why React Was Created

Before React, developers used traditional JavaScript or libraries like jQuery.

Problem with old approach:

  • Direct DOM manipulation was slow
  • Code became messy
  • UI state was hard to manage
  • Reusing UI was difficult

Imagine this:

HTML
<button id="btn">Like</button>
<p id="count">0</p>

Traditional

JavaScript
let count = 0;
document.getElementById("btn").addEventListener("click", () => {
count++;
document.getElementById("count").innerText = count;
});

This works for small apps.

But imagine:

  • Facebook feed
  • Instagram
  • Netflix
  • Gmail

Thousands of UI updates happen constantly.

Managing DOM manually becomes very difficult.

React solved this problem.

---

Core Concepts of React

---

1. Component-Based Architecture

React applications are built using components.

A component is an independent reusable UI block.

Example:

JSX
function Header() {
return <h1>My Website</h1>;
}
function Footer() {
return <p>Copyright 2026</p>;
}
function App() {
return (
<div>
<Header />
<Footer />
</div>
);
}

--- Here:

  • Header is a component
  • Footer is another component
  • App combines them

Benefits:

  • Reusability
  • Cleaner code
  • Easy maintenance
  • Scalable architecture

---

2. JSX (JavaScript XML)

React uses JSX.

JSX allows writing HTML inside JavaScript.

Example:

JSX
const element = <h1>Hello React</h1>;

Without JSX:

JavaScript
const element = React.createElement(
"h1",
null,
"Hello React"
);

JSX makes code:

  • More readable
  • Easier to write
  • Similar to HTML

---

Important Interview Point

JSX is NOT HTML.

It gets converted into JavaScript by Babel.

Example conversion:

JSX
<h1>Hello</h1>

becomes:

JavaScript
React.createElement("h1", null, "Hello");

---

3. Virtual DOM

This is one of the MOST IMPORTANT interview topics.

What is DOM?

DOM = Document Object Model

Browser converts HTML into a tree structure.

Example:

HTML
<body>
<h1>Hello</h1>
</body>

DOM Tree:

TEXT
body
└── h1
└── Hello

Updating real DOM is expensive.

---

React Solution → Virtual DOM

React creates a lightweight copy of the real DOM called Virtual DOM.

Process:

  1. React creates Virtual DOM
  2. State changes
  3. React creates new Virtual DOM
  4. React compares old vs new (Diffing)
  5. React updates only changed parts

This process is called:

Reconciliation

---

Example

JSX
function App() {
const [count, setCount] = React.useState(0);
return (
<div>
<h1>{count}</h1>
<button onClick={() => setCount(count + 1)}>
Increment
</button>
</div>
);
}

When button clicked:

  • React updates only <h1>
  • Entire page does NOT reload

This improves performance.

---

4. State in React

State = data managed inside component.

Example:

JSX
function Counter() {
const [count, setCount] = React.useState(0);
return (
<div>
<p>{count}</p>
<button onClick={() => setCount(count + 1)}>
Increase
</button>
</div>
);
}

---

JSX
const [count, setCount] = React.useState(0);

Meaning:

  • count → current value
  • setCount → function to update value
  • 0 → initial value

---

5. Props in React

Props = data passed from parent to child component.

Example:

JSX
function User(props) {
return <h1>Hello {props.name}</h1>;
}
function App() {
return <User name="Aman" />;
}

Output:

TEXT
Hello Aman

---

Important Interview Difference

FeaturePropsState
Mutable?NoYes
Managed byParentComponent itself
PurposePass dataStore data

---

6. React Hooks

Hooks allow functional components to use React features.

Most important hooks:

  • useState
  • useEffect
  • useRef
  • useMemo
  • useCallback
  • useContext

---

useEffect Example

JSX
import { useEffect } from "react";
function App() {
useEffect(() => {
console.log("Component mounted");
}, []);
return <h1>Hello</h1>;
}

--- useEffect handles:

  • API calls
  • Timers
  • Side effects
  • Event listeners

---

7. One-Way Data Binding

React follows:

Parent → Child Data Flow

Data flows in one direction only.

Benefits:

  • Easier debugging
  • Predictable behavior
  • Better state management

---

8. React is Declarative

Imperative approach:

JavaScript
document.getElementById("box").style.color = "red";

Declarative approach in React:

JSX
const isRed = true;
return (
<div style={{ color: isRed ? "red" : "blue" }}>
Hello
</div>
);

You describe:

  • WHAT UI should look like

React decides:

  • HOW to update DOM

---

React Lifecycle (Important)

Class Components had lifecycle methods:

JavaScript
componentDidMount()
componentDidUpdate()
componentWillUnmount()

Modern React uses Hooks:

JSX
useEffect(() => {
// Mount
return () => {
// Unmount cleanup
};
}, []);

---

Why Companies Use React

Big companies using React:

  • Meta
  • Netflix
  • Airbnb
  • Uber
  • WhatsApp

Reasons:

  • Fast rendering
  • Reusable components
  • Huge ecosystem
  • Strong community
  • SEO support with frameworks like Next.js

---

2. Forgetting Key in Lists ❌

Wrong:

JSX
items.map(item => <li>{item}</li>)

Correct:

JSX
items.map(item => (
<li key={item.id}>{item.name}</li>
))

Keys help React identify elements efficiently.

---

3. Too Many Re-renders

Wrong:

JSX
setCount(count + 1);

inside render body.

This causes infinite loop.

---

4. Using Props as State

Wrong:

JSX
const [name, setName] = useState(props.name);

Usually unnecessary duplication.

---

5. Not Understanding Dependency Array

Wrong:

JSX
useEffect(() => {
fetchData();
});

Runs every render.

Correct:

JSX
useEffect(() => {
fetchData();
}, []);

Runs once.

---

React Interview Questions You MUST Know

Advanced Code Example

Step 1 → useState

JSX
const [todos, setTodos] = useState([]);

Stores todo list.

---

Step 2 → Input State

JSX
const [input, setInput] = useState("");

Stores current textbox value.

---

Step 3 → Controlled Component

JSX
<input
value={input}
onChange={(e) => setInput(e.target.value)}
/>

React controls input value.

This is called:

Controlled Component

---

Step 4 → Adding Todo

JSX
setTodos([...todos, newTodo]);

...todos copies previous array.

New todo appended.

---

Step 5 → Rendering List

JSX
todos.map(todo => (
<li key={todo.id}>
{todo.text}
</li>
))

React renders dynamically.

---

Difference Between React and Angular

FeatureReactAngular
TypeLibraryFramework
LanguageJavaScriptTypeScript
DOMVirtual DOMReal DOM
Learning CurveEasierHarder
FlexibilityHighModerate

---

Difference Between React and Vue

FeatureReactVue
FlexibilityHighModerate
CommunityLargerSmaller
JSXYesOptional
LearningModerateEasy

---

React Ecosystem

Common libraries used with React:

PurposeLibrary
RoutingReact Router
State ManagementRedux, Zustand
API CallsAxios
StylingTailwind CSS
FormsReact Hook Form
Backend IntegrationFirebase

---

Important React Terms

TermMeaning
ComponentReusable UI block
JSXHTML-like syntax
PropsParent-to-child data
StateDynamic component data
HooksFunctions for React features
Virtual DOMLightweight DOM copy
ReconciliationDOM diffing process

---

Final Interview Summary

If interviewer asks:

Real-world example

Example: E-Commerce Website

Imagine building Amazon.

Components:

TEXT
App
├── Navbar
├── Sidebar
├── ProductList
│ ├── ProductCard
│ ├── ProductCard
│ └── ProductCard
└── Footer

Each product card is reusable.

Example:

JSX
function ProductCard({ name, price }) {
return (
<div>
<h2>{name}</h2>
<p>{price}</p>
</div>
);
}

Usage:

JSX
<ProductCard name="iPhone" price="$1000" />
<ProductCard name="Laptop" price="$2000" />

---

Common mistakes

  • ## 1. Mutating State Directly ❌
  • Wrong:
  • ```jsx
  • count = count + 1
  • ```
  • Correct:
  • ```jsx
  • setCount(count + 1)
  • ```
  • Reason:
  • React re-renders only when setter function used.
  • ---
  • ## Beginner
  • 1. What is React?
  • 2. What is JSX?
  • 3. Difference between state and props?
  • 4. What is Virtual DOM?
  • 5. What are hooks?
  • 6. What is useEffect?
  • 7. Why keys are important?
  • ---
  • ## Intermediate
  • 1. What is reconciliation?
  • 2. Controlled vs uncontrolled components
  • 3. Lifting state up
  • 4. Memoization
  • 5. useMemo vs useCallback
  • 6. Context API
  • 7. React Router
  • ---
  • ## Advanced
  • 1. Fiber architecture
  • 2. Server-side rendering
  • 3. Hydration
  • 4. Concurrent rendering
  • 5. React performance optimization
  • 6. Redux vs Context API
  • 7. React Suspense
  • ---
  • ## Todo App
  • ```jsx
  • import React, { useState } from "react"
  • function TodoApp() {
  • const [todos, setTodos] = useState([])
  • const [input, setInput] = useState("")
  • const addTodo = () => {
  • const newTodo = {
  • id: Date.now(),
  • text: input
  • }
  • setTodos([...todos, newTodo])
  • setInput("")
  • }
  • return (
  • <div>
  • <input
  • value={input}
  • onChange={(e) => setInput(e.target.value)}
  • />
  • <button onClick={addTodo}>
  • Add
  • </button>
  • <ul>
  • {todos.map(todo => (
  • <li key={todo.id}>
  • {todo.text}
  • </li>
  • ))}
  • </ul>
  • </div>
  • )
  • }
  • export default TodoApp
  • ```
  • ---

Follow-up questions

  • What is the difference between React and React Native?
  • Why is Virtual DOM faster?
  • What is component re-rendering?
  • What are controlled components?
  • Explain hooks in detail.
  • Explain useMemo with example.
  • Explain Context API.
  • Explain Redux flow.
  • What causes unnecessary re-renders?
  • Explain React Router.

More React interview questions

View all →