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:
function App() { return <h1>Hello World</h1>;}This code creates a UI component that displays:
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:
<button id="btn">Like</button><p id="count">0</p>Traditional
let count = 0;
document.getElementById("btn").addEventListener("click", () => { count++; document.getElementById("count").innerText = count;});This works for small apps.
But imagine:
- Facebook feed
- 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:
function Header() { return <h1>My Website</h1>;}
function Footer() { return <p>Copyright 2026</p>;}
function App() { return ( <div> <Header /> <Footer /> </div> );}--- Here:
Headeris a componentFooteris another componentAppcombines them
Benefits:
- Reusability
- Cleaner code
- Easy maintenance
- Scalable architecture
---
2. JSX (JavaScript XML)
React uses JSX.
JSX allows writing HTML inside JavaScript.
Example:
const element = <h1>Hello React</h1>;Without JSX:
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:
<h1>Hello</h1>becomes:
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:
<body> <h1>Hello</h1></body>DOM Tree:
body └── h1 └── HelloUpdating real DOM is expensive.
---
React Solution → Virtual DOM
React creates a lightweight copy of the real DOM called Virtual DOM.
Process:
- React creates Virtual DOM
- State changes
- React creates new Virtual DOM
- React compares old vs new (Diffing)
- React updates only changed parts
This process is called:
Reconciliation
---
Example
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:
function Counter() { const [count, setCount] = React.useState(0);
return ( <div> <p>{count}</p>
<button onClick={() => setCount(count + 1)}> Increase </button> </div> );}---
const [count, setCount] = React.useState(0);Meaning:
count→ current valuesetCount→ function to update value0→ initial value
---
5. Props in React
Props = data passed from parent to child component.
Example:
function User(props) { return <h1>Hello {props.name}</h1>;}
function App() { return <User name="Aman" />;}Output:
Hello Aman---
Important Interview Difference
| Feature | Props | State |
|---|---|---|
| Mutable? | No | Yes |
| Managed by | Parent | Component itself |
| Purpose | Pass data | Store data |
---
6. React Hooks
Hooks allow functional components to use React features.
Most important hooks:
useStateuseEffectuseRefuseMemouseCallbackuseContext
---
useEffect Example
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:
document.getElementById("box").style.color = "red";Declarative approach in React:
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:
componentDidMount()componentDidUpdate()componentWillUnmount()Modern React uses Hooks:
useEffect(() => {
// Mount
return () => { // Unmount cleanup };
}, []);---
Why Companies Use React
Big companies using React:
- Meta
- Netflix
- Airbnb
- Uber
Reasons:
- Fast rendering
- Reusable components
- Huge ecosystem
- Strong community
- SEO support with frameworks like Next.js
---
2. Forgetting Key in Lists ❌
Wrong:
items.map(item => <li>{item}</li>)Correct:
items.map(item => ( <li key={item.id}>{item.name}</li>))Keys help React identify elements efficiently.
---
3. Too Many Re-renders
Wrong:
setCount(count + 1);inside render body.
This causes infinite loop.
---
4. Using Props as State
Wrong:
const [name, setName] = useState(props.name);Usually unnecessary duplication.
---
5. Not Understanding Dependency Array
Wrong:
useEffect(() => { fetchData();});Runs every render.
Correct:
useEffect(() => { fetchData();}, []);Runs once.
---
React Interview Questions You MUST Know
Advanced Code Example
Step 1 → useState
const [todos, setTodos] = useState([]);Stores todo list.
---
Step 2 → Input State
const [input, setInput] = useState("");Stores current textbox value.
---
Step 3 → Controlled Component
<input value={input} onChange={(e) => setInput(e.target.value)}/>React controls input value.
This is called:
Controlled Component
---
Step 4 → Adding Todo
setTodos([...todos, newTodo]);...todos copies previous array.
New todo appended.
---
Step 5 → Rendering List
todos.map(todo => ( <li key={todo.id}> {todo.text} </li>))React renders dynamically.
---
Difference Between React and Angular
| Feature | React | Angular |
|---|---|---|
| Type | Library | Framework |
| Language | JavaScript | TypeScript |
| DOM | Virtual DOM | Real DOM |
| Learning Curve | Easier | Harder |
| Flexibility | High | Moderate |
---
Difference Between React and Vue
| Feature | React | Vue |
|---|---|---|
| Flexibility | High | Moderate |
| Community | Larger | Smaller |
| JSX | Yes | Optional |
| Learning | Moderate | Easy |
---
React Ecosystem
Common libraries used with React:
| Purpose | Library |
|---|---|
| Routing | React Router |
| State Management | Redux, Zustand |
| API Calls | Axios |
| Styling | Tailwind CSS |
| Forms | React Hook Form |
| Backend Integration | Firebase |
---
Important React Terms
| Term | Meaning |
|---|---|
| Component | Reusable UI block |
| JSX | HTML-like syntax |
| Props | Parent-to-child data |
| State | Dynamic component data |
| Hooks | Functions for React features |
| Virtual DOM | Lightweight DOM copy |
| Reconciliation | DOM diffing process |
---
Final Interview Summary
If interviewer asks:
Real-world example
Example: E-Commerce Website
Imagine building Amazon.
Components:
App ├── Navbar ├── Sidebar ├── ProductList │ ├── ProductCard │ ├── ProductCard │ └── ProductCard └── FooterEach product card is reusable.
Example:
function ProductCard({ name, price }) { return ( <div> <h2>{name}</h2> <p>{price}</p> </div> );}Usage:
<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.