Leanpub Header

Skip to main content

可维护的React

重构至整洁代码

了解如何识别 React 中最常见的代码坏味道,以及将它们重构为更优雅和可维护的正确方法。 请记住,在大多数情况下,您是代码的读者,因此请通过学习和应用本书中讨论的有用技术来善待自己。

This book is a translation into Chinese (Simplified) of Maintainable React which was originally written in English

The author is letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
207
Readers
126
Pages
5,239Words
About

About

About the Book

我们都知道,任何实际项目中最重要的编码工作都不是编写新代码,而是维护现有代码。 我们有相当一部分时间花在试图理解遗留代码上。

在这本书中,我试图将我在我从事的许多 React 项目中发现的常见模式放在一起:哪些有效,哪些无效,问题的症状以及如何使用经过验证的技术摆脱它们。

我希望它可以帮助您应对项目的挑战,节省编写新功能的时间,并在每次提交时改进代码库。

Share this book

This book is a translation into Chinese (Simplified) of Maintainable React which was originally written in English

Price

Pick Your Price...

Minimum price

$7.99

$9.99

You pay

$9.99

Author earns

$7.99
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 1)

1
The author will earn $12.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Author

Juntao Qiu

Hi, I'm Juntao, and I help developers write better code through clear, practical guidance.

I am deeply committed to contributing to both the online and offline developer communities, sharing insights and knowledge gleaned from my experiences in various projects. Among my contributions are several publications focused on Web Development. Notably, my latest works include "React Anti-Patterns" (2024), "Test-Driven Development with React (2nd)" (2023) and "Maintainable React" (2022).

Additionally, I host a YouTube channel (@icodeit.juntao), where I delve into Clean Code practices and Refactoring techniques, aiming to assist developers in honing their coding skills.

Contents

Table of Contents

前言

  1. 又一本关于重构的书?
  2. 本书的结构

React里的整洁代码

  1. 什么是整洁代码
  2. 整洁代码
  3. 小结
  4. 参考

测试驱动开发简介

  1. 红-绿-重构
  2. 典型流程
  3. 一个例子
  4. 小结

实例Todo应用 - 基本功能

  1. 开始之前
  2. 渲染一个待办条目
  3. 渲染多条待办事项
  4. 数据结构
  5. 为列表添加新的条目
  6. 小结

重构 - 关注点分离

  1. 关注点分离原则
  2. 抽取新的组件
  3. 在Todo中使用新组件
  4. 小结

新需求 - 完成待办事项

  1. 添加测试
  2. 类型更新
  3. 响应条目的点击事件
  4. 过滤已完成的条目
  5. 小结

重构 - 使用hook来分离逻辑

  1. 再次重构
  2. 抽取TodoList组件
  3. 自定义hook负责业务逻辑
  4. 小结

组合的基础

  1. chillren属性和插槽模式
  2. 插槽模式
  3. 小结

重构AddressContainer

  1. 使用render属性进行解耦
  2. 更高级一些的渲染逻辑
  3. 小结

可组合性实例1 - 头像组件

  1. Tooltip属性
  2. 打破依赖
  3. 小结

可组合性实例2 - 内联编辑器

  1. validate属性
  2. 方案1 - 添加新的控制属性
  3. 方案2 - 扩展已有的render属性
  4. 小结

StackView组件的重构

  1. StackView
  2. 测试
  3. 将页眉页脚变成可选项
  4. 新需求 - 用户Profile页
  5. 你觉得这个代码有问题吗?
  6. 先破后立
  7. 小结

何处安放你的业务逻辑

  1. 全能的视图
  2. 逻辑的泄漏
  3. 小结

查漏补缺 - 数据建模

  1. 一个地址搜索框
  2. 小结
  3. 参考

后备箱速递

  1. 测试先行
  2. 测试按钮是否存在
  3. Mocks
  4. 实现组件
  5. 小结

通知商店

  1. 重构
  2. 自定义hook
  3. 小结

错误响应

  1. 通知消息
  2. 审视之
  3. 小结

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub