Organizing code
There are many ways you can organize your code. Now, one thing we need to be aware of is choosing patterns that save you some time and make your code better in the long run. This section will discuss three different patterns that we can leverage together or independently to make our code more structured, readable, and organized. Here’s what we will discuss in this section:
- Creating an API file
- Leveraging query key factories
- Creating a hooks folder
Creating an API file
Creating an API file to contain all my requests for a specific domain is a pattern that I follow.
In this file, I leverage my API client and create the functions responsible to make a request to a given route and return the request data.
This is particularly useful because it avoids repeating the logic for the same request in your code and focuses all the domain-specific requests in the same file.
For all the requests made in the scope of this book, I would prefer...