Learning React (2nd Edition)
Tags
Summary
This book is the Chinese edition of the second edition of O'Reilly's classic front-end technology book Learning React, aimed at developers who already write JavaScript and know the basics of HTML and CSS but have not yet systematically encountered React or functional JavaScript. The book has 12 chapters; the first half spends considerable space re-teaching syntax fundamentals: variable declarations since ES6, template strings, default parameters, arrow functions, destructuring assignment, the spread operator, Promises, classes, and modules, then moves into core concepts of functional programming, including immutability, pure functions, data transformation, higher-order functions, recursion, and composition. Only after laying a solid language foundation does the book turn to React itself: the meaning of the virtual DOM and React elements, setting up a build process with JSX, Babel, and webpack, components, props, state, and the component tree, property validation, refs and the reverse flow of data, then the component lifecycle, making requests with fetch, integrating third-party libraries such as D3, higher-order components, and the ideas behind Flux. The second half unfolds in turn Redux (actions, reducers, stores, middleware), React Redux's Provider and connect, testing and snapshot testing with ESLint and Jest, React Router's routing and nested routes, and finally server-side rendering and isomorphic (universal) applications. The whole book ties the code of each chapter together with a single running color-management example, making it a rare React tutorial that builds completely "from language to architecture." Compared with the first edition, this edition adds explanations of modern approaches such as Hooks.
Editor's review
市面上的 React 书大致分两类:一类是「快速上手」,直接把你丢进 JSX 和 Hooks;另一类是「讲清来路」,先解释这门库为什么长成今天的样子。这本属于后者,这也是它最值得推荐的地方。 作者用前三章的篇幅处理 ES6 与函数式编程。不可变性、纯函数、高阶函数、函数组合这些概念,很多人是在写 React 时被反复踩坑才补上的,而在本书里它们先于 React 出现,后面讲到 reducer 与 state 管理时你会明显感到顺畅。第 4 到第 7 章从虚拟 DOM、React 元素一路讲到组件树中数据的上下流动、生命周期与高阶组件,配合一套贯穿全书的配色管理案例,代码是一点点长出来的,不是零散片段。 后半本的价值在于「整条链路」:Redux 的概念与中间件、React Redux 的 Provider 与 connect、ESLint 与 Jest 下的测试与快照测试、React Router 的嵌套路由,最后用两章讲服务端渲染与同构应用。这种从语言基础到可选架构的完整路径,是很多入门书不愿花篇幅去做的。 需要提醒的是,作为 2021 年出版的译本,它对 Hooks 与函数组件的覆盖不如专门的 Hooks 主题书深入,示例中的部分工具链版本也已显旧;但正因成书早于 React 生态的大幅简化,它对「为什么需要 Redux、为什么需要同构」的解释反而更扎实。适合当作打地基的一本,配合官方文档一起读。
Who it's for
A good fit for
- 已会写 JavaScript,但没系统用过 React 的前端开发者
- 想补上函数式编程与 ES6 基础、再学框架的自学者
- 需要理解 Redux、路由、服务端渲染完整链路的工程师
- 计算机相关专业学生或转行前端的求职者
Not a good fit for
- 完全没有 JavaScript 基础、零编程经验的读者
- 只想要 Hooks 与最新函数组件写法、追求即刻上手的人
- 需要 TypeScript 或 React Server Components 等新主题的进阶读者
Reading tips
- 先读完前三章语言与函数式部分并动手敲示例,不要跳过
- 跟着书中的配色管理案例逐步搭建项目,比零散读代码收获大
- 读到 Redux 与同构章节时对照官方文档,注意工具链版本差异
- 把本书当作地基读物,配合 React 官方文档的 Hooks 部分使用
Contents
- Preface
- Chapter 1 Getting Started with React
- 1.1 A Solid Foundation
- 1.2 React's Past and Future
- 1.3 Resources
- 1.3.1 The Resource Repository
- 1.3.2 React Developer Tools
- 1.3.3 Installing Node.js
- Chapter 2 New JavaScript Features
- 2.1 Variable Declarations in ES6
- 2.2 Arrow Functions
- 2.3 Transpiling ES6
- 2.4 ES6 Objects and Arrays
- 2.5 Promises
- 2.6 Classes
- 2.7 ES6 Modules
- Chapter 3 Functional JavaScript
- 3.1 What Is Functional Programming
- 3.2 Imperative and Declarative
- 3.3 Basic Concepts of Functional Programming
- Chapter 4 Advanced React
- 4.1 Building a Page
- 4.2 The Virtual DOM
- 4.3 React Elements
- 4.4 ReactDOM
- 4.5 Children
- 4.6 Constructing Elements with Data
- 4.7 React Components
- 4.8 Rendering to the DOM
- Chapter 5 React and JSX
- 5.1 React Elements and JSX
- 5.2 JSX Tips
- 5.3 Babel
- 5.4 Recipes and JSX
- 5.5 Introduction to Webpack
- Chapter 6 Props, State, and the Component Tree
- 6.1 Property Validation
- 6.2 Refs
- 6.3 React State Management
- 6.4 Internal State in the Component Tree
FAQ
这本书需要有 JavaScript 基础吗?
需要。书中前几章会系统梳理 ES6 语法与函数式概念,但默认你已能读懂基本语法、了解 HTML 与 CSS 在浏览器中的作用,否则会被示例节奏甩开。
第二版和初版有什么区别?哪个版本更好?
初版由邓世超翻译,2017 年出版,ISBN 9787519814236,共 318 页;第二版由安道翻译,2021 年出版,共 361 页,ISBN 9787519856540,补充了 Hooks 等现代写法,内容更新,建议选第二版。
这本书讲的是 Hooks 还是类组件?
两者都有。第二版在组件、状态管理与数据获取部分引入了 Hooks,同时保留大量类组件与生命周期讲解,因此读起来能看到 React 从类组件向函数组件过渡的完整脉络。
书里的技术内容现在会不会过时?
书中 webpack、Babel 配置与部分工具版本已显旧,Redux 的写法也非最新推荐方式;但虚拟 DOM、组件树、纯函数 reducer、同构渲染等原理性内容并不过时,建议对照官方文档同步更新写法。
适合用来准备前端面试吗?
可以作为原理层面的补充。它对组件树数据流、生命周期、Redux 数据流、服务端渲染的解释较为完整,但缺少算法题与最新框架特性,面试准备还需另配资料。
Comments
Find this book
This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.