This example demonstrates why fetching data with useEffect can lead to problems. Try changing categories quickly to observe race conditions.
If you quickly switch between categories, responses might come back in a different order than requested. The component has no way to know which request is the latest.
Solution: Use an "ignore" flag in a cleanup function to ignore stale responses.
We need to manually track loading, error, and success states with separate useState hooks, creating boilerplate code.
It's difficult to distinguish between "we haven't loaded data yet" and "the query returned no results."
Solution: Initialize data state to undefined instead of an empty array.
When an error occurs, we often don't clear previous data, leading to potentially displaying stale information.
Solution: Reset data state when errors occur and reset error state when data loads successfully.