Review of "React Anti-patterns" by Juntao Qiu

Review of "React Anti-patterns" by Juntao Qiu

·

4 min read

💡
Juntao Qiu is an accomplished software developer with over 15 years of industry experience, dedicated to helping others write better code. With a strong passion for crafting maintainable and high-quality code, he has become a trusted resource in the industry. As an author, Juntao has shared his expertise through influential books such as Maintainable React (2022) and Test-Driven Development with React and TypeScript – Second Edition (2023).

If you are working with React.js and you want to build robust and maintainable applications, the book “React Anti-patterns“ by Juntao Qiu can help you. This book is a valuable resource that supports React developers in identifying common anti-patterns and addressing them efficiently using established design patterns and principles.

The book is divided into 4 parts across 13 chapters:

  • Part 1: Introducing the Fundamentals

  • Part 2: Embracing Testing Techniques

  • Part 3: Unveiling Business Logic and Design Patterns

  • Part 4: Engaging in Practical Implementation

In the first part, the author introduces common anti-patterns that React developers might encounter, including:

  • Props drilling: The practice of passing props from a parent component through multiple intermediary components before they reach the child component that actually needs them.

  • In-component data transformation: Occurs when developers introduce complex data transformation logic directly within components

  • Complicated logic in views: The infusion of business logic within view components.

  • Lack of tests

  • Duplicated code

  • Long component with too much responsibility

The author not only lists these common anti-patterns and explains their concepts but also guides us on how to tackle them effectively. Another challenge that React developers might face is project structure—that is, how to organize a React application. As projects grow, a less-structured organization can lead to many issues such as code smells and increased complexity. Juntao Qiu introduces common structures in React applications, including feature-based structure, component-based structure, atomic design structure and MVVM structure, along with their respective pros and cons.

Part 2 of the book focuses on testing in React applications. By outlining the benefits of testing, the author explains why tests are a critical part of building reliable and maintainable software—testing is not just an optional best practice. In this part, the book walks us through basic types of tests in a frontend application: unit tests, integration tests and end to end tests. One of the most valuable chapters in this part is Chaper 6.—Exploring Common Refactoring Techniques, in which the author guides us through the most common refactoring techniques. By applying these techniques, we can improve the codebase’s readability, maintainability and ease of testing. In the final chapter of this part, the author introduces one of the most common concepts in software development: Test-Driven Development (TDD), and explains how to apply this approach to React projects step by step.

In Part 3, we will learn to manage business logic—the aspect that can make React applications complex and less readable if not handled carefully. The author introduces the concept of Anti-Corruption Layers (ACL), along with fundamental design principles like Single Responsibility Principle (SRP), Dependency Inversion Principle to tackle common challenges in state management. In the remainder of this part, we will dive into the composition pattern in React by using High-Order Component (HOC) and Headless Component, with practical examples.

In the final part of the book, the author brings the discussed concepts to life with practical implementations. First, Juntao Qiu guides us on implementing layered architecture with a pizza ordering application. We will see the benefits of separating a React application into different layers: a view layer for rendering the UI, hooks for state management and models for calculations. Second, we learn how to implement an end-to-end weather application where we will apply all techniques, patterns and principles covered in this book.

In conclusion, this is a useful book for React developers who are interested in improving the readability and maintainability of their code—whether they’re just starting out or already experienced. To read the full book, you can purchase it here: React Anti-Patterns: Build efficient and maintainable React applications with test-driven development and refactoring.