Skip to content

React Overview

什么 React 是, 它的核心 philosophy, and 为什么它 dominates modern 前面-端 development.

你将学到

  • 什么 React 是 and problems 它解决
  • 组件-based 架构 and 虚拟 DOM
  • 如何 React differs 从 vanilla JavaScript and other 框架
  • React ecosystem and 哪里到 go 下一个

概念讲解

什么是 React?

React is a declarative, component-based JavaScript library for building user interfaces. Created by Facebook (now Meta) in 2013, it has become the most popular front-end library in the world. Unlike a full framework like Angular, React is focused on one thing: rendering UI. You bring your own routing, state management, and build tooling, which gives you flexibility.

The Core Ideas

React is built on three foundational concepts. Declarative means you describe what the UI should look like for any given state, and React figures out how to update the DOM to match. Component-based means you build encapsulated, reusable pieces of UI and compose them together like Lego blocks. The Virtual DOM is an in-memory representation of the real DOM; React diffs the previous and next virtual DOM trees and applies only the minimal set of changes to the real DOM, which is much faster than direct DOM manipulation.

Why React Instead of Vanilla JS?

In vanilla JavaScript, you manually query DOM elements, attach event listeners, and imperatively update the DOM as data changes. This becomes unmanageable for complex, stateful UIs. React lets you write UI = f(状态) — the UI is a pure function of state. When state changes, React automatically re-renders the affected parts. This mental model scales from a simple counter to a massive dashboard.

The React Ecosystem

React itself is small. Around it sits a rich ecosystem: Create React App and Vite for scaffolding, React Router for navigation, Redux or Zustand for global state, Next.js for server-side rendering, and React DevTools for debugging. Learning React opens the door to React Native (mobile), Remix, and many other tools.

Getting Started

To create a new React project, the recommended approach is to use Vite: run npm 创建 vite@latest my-app -- --template react and you have a fully configured development environment in seconds. Vite provides instant server start, lightning-fast hot module replacement, and optimized production builds. Alternatively, Next.js offers a more opinionated, full-stack starting point with server-side rendering built in.

示例代码

              // A minimal React component — the building block of every React app.
import React from "react";

function Welcome({ name }) {
  return <h1>Hello, {name}!</h1>;
}

// Compose components together like building blocks.
function App() {
  return (
    <div>
      <Welcome name="Alice" />
      <Welcome name="Bob" />
      <Welcome name="CoderNewbie" />
    </div>
  );
}

export default App;
            

这个是 JSX — 语法 extension 那个 lets 你编写 HTML-如 markup 内部 JavaScript. 每个 Welcome 组件是 reusable and 接收数据通过 Props.

动手试一试

  • JSON Formatter

    React 组件 Props 经常 come 从 JSON — 练习格式化它.

  • Code Diff

    Compare two versions 的组件到 see 什么更改.

常见错误

错误写法

Thinking React 是完整框架如 Angular

正确做法

React 是库 for 构建 UIs. Routing, 状态 management, and 数据获取是 handled 通过 separate ecosystem 包你 选择你自己.

错误写法

Confusing 虚拟 DOM 使用真实 DOM

正确做法

虚拟 DOM 是 in-memory 树 React maintains. 你很少 touch 真实 DOM directly in React — let React handle reconciliation.

练习 React Overview

3 个练习

练习 React Overview

查阅不认识的术语

新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。

查看术语表

动手做项目

通过引导式项目应用所学,含起始代码与解决方案。

查看项目

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误