Book Image

React Design Patterns and Best Practices

By : Michele Bertoli
Book Image

React Design Patterns and Best Practices

By: Michele Bertoli

Overview of this book

Taking a complete journey through the most valuable design patterns in React, this book demonstrates how to apply design patterns and best practices in real-life situations, whether that’s for new or already existing projects. It will help you to make your applications more flexible, perform better, and easier to maintain – giving your workflow a huge boost when it comes to speed without reducing quality. We’ll begin by understanding the internals of React before gradually moving on to writing clean and maintainable code. We’ll build components that are reusable across the application, structure applications, and create forms that actually work. Then we’ll style React components and optimize them to make applications faster and more responsive. Finally, we’ll write tests effectively and you’ll learn how to contribute to React and its ecosystem. By the end of the book, you’ll be saved from a lot of trial and error and developmental headaches, and you will be on the road to becoming a React expert.
Table of Contents (19 chapters)
React Design Patterns and Best Practices
About the Author
About the Reviewer
Customer Feedback

Chapter 5. Proper Data Fetching

The goal of this chapter is to show the different data fetching patterns that we can put in place in a React application.

To find the best strategy, we have to clearly understand how the data flows within a tree of components in React.

It is important to know how the parent can communicate with its children and the other way around. It is also crucial to understand how unconnected siblings can share their data.

We will see some real-world examples of data fetching, transforming a base component into a well-structured one using HoCs.

Finally, we will see how existing libraries such as react-refetch can save us a lot of time by providing the core data fetching functionalities we need.

In this chapter, we will cover the following topics:

  • The Unidirectional Data Flow of React and how it can make our applications easier to reason about

  • How a child can communicate with its parent using callbacks

  • The way two siblings can share data through their common parent

  • How to create...