Challenge: GitHub User Search App
Let's build a React app that allows users to search GitHub profiles efficiently while implementing data fetching, error handling, and React Query caching for performance optimization.
We'll cover the following...
Problem statement
You’re tasked to build a GitHub User Search Tool for your company’s developer dashboard. The app must let users type a GitHub username, fetch the corresponding user’s profile information (name, bio, followers, email), and display it clearly on the screen.
The product team requires the following:
Repeated searches for the same user should load instantly — served from React Query’s cache.
If the user doesn’t exist, an error message should appear.
If the user leaves the input blank and hits Search, no API request should be made.
Include a Clear button to reset the app state.
Ensure loading, error, and success states are distinct and intuitive.
Technical requirements: Implement the following features step by step:
Add a search bar to input GitHub usernames.
On clicking Search, use React Query’s
useQuery()to fetch user data via the providedfetchGitHubUser()helper.Display proper states:
Loading...message while fetching.User details on success.
Error message if the user is not found.
Implement caching and background refetch — React Query handles this automatically.
Add a Clear button to reset the input and UI state.
Expected output
Typing “octocat” → shows user card (name, bio, followers, email).
Typing the same username again → loads instantly from cache.
Searching “unknown” → shows
User not found.Clicking Clear → resets the input and clears UI state.