Leanpub Header

Skip to main content

Maintainable React

Test-Driven Development, Refactoring and Clean Code.

Struggling with messy React code? This book shows you how to refactor with confidence using real-world examples and timeless design principles—so your code stays clean, readable, and easy to change. Perfect for developers who want to level up their frontend craft.

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

Pick Your Price...
PDF
EPUB
WEB
347
Readers
126
Pages
18,198Words
About

About

About the Book

Write Clean Code in React—Without Guesswork

Modern frontend development is more complex than ever. React gives you power, but with that comes decisions: How should you structure components? What makes code "clean"? When is abstraction helpful—and when is it harmful?

This book is your practical guide to writing maintainable, readable, and flexible React code by applying proven design principles to real-world examples.

Instead of abstract theory, you'll follow step-by-step refactoring journeys—from messy, hard-to-change codebases to well-structured, thoughtful designs. Along the way, you'll learn how to spot code smells, apply small and effective refactorings, and avoid common anti-patterns.

Whether you're a developer looking to sharpen your craft or preparing for a system design interview, this book gives you a toolkit for thinking clearly about code.

Price

Pick Your Price...

Minimum price

$14.99

$24.99

You pay

$24.99

Author earns

$19.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.

Translations

Translations

Contents

Table of Contents

Preface

  1. Do we need another book on this topic?
  2. Who is this book for?
  3. How the book is structured
  4. References

Chapter 0 — React Clean Code: Embracing Elegance in Code

  1. Introduction: Why Clean Code Matters in React
  2. What Does “Clean Code” Really Mean?
  3. Symptom 1: The Long File
  4. Symptom 2: Hard to Test
  5. Symptom 3: Hard to Change
  6. Symptom 4: Ignoring Fundamental Principles
  7. What Clean Code Looks Like
  8. React-Specific Cleanup Techniques
  9. Summary: The First Step Toward Clean React Code
  10. References

Chapter 1/2 – Navigating the Growth of Your React Application

  1. Frontend Projects Are More Complex Than They Look
  2. How to Split Your Project
  3. Summary and Key Takeaways

Chapter 1 – A Brief Introduction to Test-Driven Development

  1. What Is Test-Driven Development?
  2. Where Beginners Get Stuck
  3. Writing the First Test
  4. Adding One More Test
  5. Summary

Chapter 2 – Todo Application: Building Core Features with TDD

  1. Starting the Todo Application
  2. Rendering a Single Todo Item
  3. Rendering Multiple Todo Items
  4. Using a Better Data Structure
  5. Adding a New Todo Item
  6. Improvements and Final Version
  7. A Note on File Organization
  8. Summary

Chapter 3 – Refactor: Separation of Concerns

  1. What Is Separation of Concerns?
  2. Why Separation of Concerns Matters
  3. Step 1: Extract a Component
  4. Step 2: Update the Todo Component
  5. Why This Refactoring Works
  6. Summary

Chapter 4 – Adding a New Feature: Mark Item As Done

  1. Write the Test First
  2. Tasking the Feature
  3. Step 1: Update the Type
  4. Step 2: Handle the Click
  5. Step 3: Filter Completed Items
  6. Recap: What We Just Achieved
  7. Summary

Chapter 5 – Refactor: Split Logic Into a Custom Hook

  1. Why Refactor Again?
  2. Step 1: Rename the Component
  3. Step 2: Extract a List Component
  4. Step 3: Simplify TodoInput and Move uuid
  5. Step 4: Introduce a Custom Hook
  6. Why This Matters
  7. What We’ve Learned
  8. Summary
  9. Wrapping Up

Chapter 6 – Composition Foundation

  1. The Children / Slots Pattern
  2. Why Not Just Use Props?
  3. Adding More Slots
  4. What We’ve Learned
  5. Summary

Chapter 7 - Refactor - AddressContainer

  1. Why Render Props?
  2. Using Render Prop to Decouple Logic and View
  3. Rendering With Custom Logic
  4. Summary
  5. What’s Next

Chapter 8 - Composition Example 1: The Avatar Component

  1. The Tooltip Prop
  2. Breaking the Dependency Chain
  3. Summary

Chapter 9 - Composition Example 2 - InlineEdit

  1. The InlineEdit component
  2. The validate prop
  3. Option 1: Add an invalidView prop
  4. Option 2: Extend editView with error state
  5. Summary

Chapter 10 - The Refactor of StackView Component

  1. The StackView Component
  2. Tests
  3. Optional Header and Footer Component
  4. New Requirement - the User Profile
  5. Break It Down and Reassemble It Back
  6. Summary

Chapter 11 – Business Logic Leaking

  1. Where Should Business Logic Go?
  2. React is The View
  3. What is Business Logic?
  4. Signs of Logic Leakage
  5. A Word About Habits
  6. Summary

Chapter 12 – Fix the Leakage: Data Modeling

  1. The Address Input Example
  2. Current Implementation
  3. Refactor Step 1: Separation of Concerns
  4. Refactor Step 2: Custom Hook
  5. Step 3: Model the Data
  6. Why It Matters
  7. Summary

Chapter 13 - Project Simulation: Direct To Boot

  1. Start with a Test
  2. A Disabled Button by Default
  3. Avoiding Fragile Mocks
  4. Enable Button When Order is Ready
  5. Polling Until Ready
  6. Refactor with Custom Hook
  7. Summary

Chapter 14 – Feature: Notify the Store

  1. Refactor: Treat Test Code as First-Class Code
  2. Clean Up the Component Logic
  3. Extracting a Custom Hook
  4. Summary

Chapter 15 - Error Handling

  1. Why This Needs a New State
  2. Common Mistake: Overloading Booleans
  3. Updating the User Message
  4. Refactoring: Breaking Up Conditional UI
  5. Section Abstraction
  6. Summary

Chapter 16 - What You’ve Learned

  1. What’s Next?
  2. What You’ve Learned
  3. Stay Connected

Appendix 10 Refactorings to Boost your Clean Code Efficiency

  1. The most common 10 refactorings
  2. Code smells
  3. Common Refactorings
  4. The Problem - ROT13
  5. The implementation
  6. Summary

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