React Introduction
React is a JavaScript library developed by Facebook (now Meta) and open-sourced in 2013, specifically for building user interfaces, especially single-page applications (SPAs).
React allows developers to use a declarative approach to build reusable UI components.
React's positioning
- Not a framework, but a library: React focuses on the view layer (the V in MVC), unlike Angular which provides a complete framework solution
- Component-based thinking: splitting the UI into independent, reusable components
- JavaScript-centric: everything is JavaScript, including structure, styles, and logic
Core features of React
1. Declarative programming (Declarative)
Traditional imperative programming: telling the computer how to do it
// 原生 JavaScript(命令式)
const button = document.getElementById('myButton');
button.addEventListener('click', function() {
const counter = document.getElementById('counter');
const currentValue = parseInt(counter.textContent);
counter.textContent = currentValue + 1;
});
React declarative programming: telling the computer what result you want
// React(声明式)
function Counter() {
const [count, setCount] = useState(0);
return ;
}
Advantage:
- Cleaner and more intuitive code
- Easier to understand and maintain
- Fewer errors from manually manipulating the DOM
- State and UI stay in sync
2. Componentization (Component-Based)
The core of React is component-based thinking, breaking the UI into independent, reusable, composable components, like building blocks. Each component only cares about its own state (state) and attributes (props), making the logic clear and easy to maintain.

A React application is made up of independent components, each of which:
- encapsulates its own structure, styles, and logic
- can receive input (props)
- can maintain internal state (state)
- can be reused and composed
Example
// A simple component
function
Welcome
(
{
name
}
)
{
return
<h1 Hello,{name}>!
h1
;
}
// Reuse and composition of components
function
App
(
)
{
return
(
<
div
<Welcome name
=
"Alice"
/>
<
Welcome name
=
"Bob"
/>
<
Welcome name
=
"Charlie"
/>
div
)
;
}
Advantages of componentization:
- Reusability: the same component can be used in multiple places
- Maintainability: modifying a component does not affect other parts
- Testability: independent components are easy to unit test
- Collaboration: team members can develop different components in parallel
3. Virtual DOM (Virtual DOM)
What is the Virtual DOM?
The Virtual DOM is a JavaScript object representation of the real DOM, a lightweight in-memory data structure.
How it works:
1. 状态改变
↓
2. 生成新的虚拟 DOM 树
↓
3. 与旧虚拟 DOM 树进行对比(Diffing)
↓
4. 计算出最小差异(Reconciliation)
↓
5. 只更新真实 DOM 中变化的部分

Illustration:
- The Virtual DOM is a lightweight JavaScript object representation of the browser DOM.
- When state changes, the framework (such as React) first performs computation and comparison in the Virtual DOM (diff algorithm).
- Then, through the patch process, only the minimal necessary updates are applied to the Real DOM.
Why is the Virtual DOM needed?
Problems with real DOM manipulation:
- DOM manipulation is very slow (compared to JavaScript computation)
- Frequent DOM operations cause page reflows and repaints
- Direct DOM manipulation is error-prone
Advantages of the Virtual DOM:
- Performance optimization: batched updates, reducing the number of real DOM operations
- Cross-platform: the Virtual DOM can render to different platforms (Web, mobile, desktop)
- Declarative: developers only need to care about state, without manually manipulating the DOM
Example Comparison:
// 假设要更新 1000 个列表项
const items = Array(1000).fill(0).map((_, i) => i);
// Traditional way: operating on the real DOM every time (slow)
items.forEach(item => {
const li = document.createElement('li');
li.textContent = item;
ul.appendChild(li); // 1000 次 DOM 操作
});
// React way: batch updates through virtual DOM
function ItemList() {
return (
{items.map(item => - {item}
)}
);
}
// React intelligently batches DOM updates
4. Unidirectional data flow (Unidirectional Data Flow)
React's data flows unidirectionally downward, Parent → Child, and Child cannot flow back to Parent:

React uses a top-down data flow approach:
父组件
↓ (props)
子组件
↓ (props)
孙组件
Feature:
- Data flows from parent components to child components
- Child components communicate with parent components via callback functions
- Data flow is clear, making it easy to trace and debug
Example
function
Parent
(
)
{
const
[
message
,
setMessage
]
=
useState
(
'Hello'
)
;
return
(
<
Child
message
=
{
message
}// Data flows downward
onUpdate
=
{
setMessage
}
// Communicate upward via callbacks
/>
)
;
}
function
Child
(
{
message
,
onUpdate
}
)
{
return
(
<
div
<
p
{
message
}
p
<button onClick
=
{
(
)
=>
onUpdate
(
'Updated!'
)
}
Update
button
div
)
;
}
Main advantages of React
1. Relatively gentle learning curve
- Fewer core APIs
- Mainly uses JavaScript knowledge
- Clear concepts and comprehensive documentation
2. A powerful ecosystem
- Routing:React Router
- State management:Redux, Zustand, Jotai
- UI libraries:Material-UI, Ant Design, Chakra UI
- Toolchain:Create React App, Vite, Next.js
3. Broad community support
- One of the most popular front-end libraries on GitHub
- A large number of third-party components and tools
- An active community and rich learning resources
4. Excellent performance
- Virtual DOM optimization
- On-demand rendering
- Support for code splitting and lazy loading
5. Cross-platform capability
- React Native: developing mobile applications
- React Native for Windows: desktop applications
- React 360: VR applications
6. Enterprise-level application support
Used by many well-known companies:
- Facebook/Meta
- Netflix
- Airbnb
- Uber
- Tencent, Alibaba, and others
When to use React
Scenarios suitable for React:
- Single-page application (SPA)
- Dynamic interfaces that need frequent updates
- Complex interactive UIs
- Large projects that need component reuse
- Applications that need cross-platform development
Scenarios less suitable for React:
- Simple static websites (may be over-engineering)
- Websites with very high SEO requirements (need to be combined with SSR solutions such as Next.js)
- Teams unfamiliar with JavaScript
React compared with other frameworks
| Feature | React | Vue | Angular |
|---|---|---|---|
| Type | library | Progressive framework | Complete framework |
| Learning curve | Medium | Gentler | Steeper |
| Flexibility | High | Medium | Low (many conventions) |
| Ecosystem | Very rich | Rich | Full integration |
| Enterprise support | Meta | independent | |
| TypeScript | Well supported | Well supported | Native support |
The development history of React
- 2013: React open-sourced
- 2015: React Native released
- 2016: React 16 (Fiber architecture)
- 2019: React Hooks officially released
- 2020: Experimental concurrent mode
- 2022: React 18 (concurrent rendering)
- 2024-2025: React Compiler, Server Components, and other new features