Building a User Dashboard
Introduction: Why User Stats Matter
Welcome back! So far, you have learned how to fetch and display a user’s reading shelf, update progress optimistically, edit shelf status, and validate forms. In this lesson, you will take the next step by building a user stats dashboard. This dashboard gives users a clear overview of their reading achievements, such as how many books they have on their shelf, how many they have completed, and their average reading progress.
A user stats dashboard is important because it helps users track their progress and stay motivated. By the end of this lesson, you will know how to fetch user stats from the backend, process the data, and display it in a visually appealing way using React components.
Our app already lets readers build a shelf, update progress with optimistic UI, edit statuses, and validate inputs with Zod + React Hook Form. The next leap is a dashboard-style overview that turns scattered data into actionable insight. A concise stats header—books on shelf, completed count, and average progress—gives users motivation, a sense of achievement, and a quick health check of their reading habits. In this lesson, you will fetch stats from the backend, normalize them for display, and present them with small, reusable React components that slot right into your existing MyShelfPage.
Building a User Dashboard
Explanation:
- The function takes a
userIdand fetches stats from the API. - The API returns
avgProgressPctas a number between 0 and 1. To make it easier to display as a percentage, the function multiplies it by 100. - The function returns a normalized
UserStatsobject, which is easier to use in your React components.
Example Output:
If the API returns:
The function will return:
