Prevent and Resolve Stale State from Async Race Conditions in React
Demonstrate and fix the classic race condition bug in React where multiple overlapping async requests (e.g., triggered by rapid search input changes) resolve out-of-order, causing stale or incorrect data to be displayed. Implement solutions using cleanup flags in useEffect, AbortController to cancel in-flight requests, and libraries like React Query. This is a critical real-world pattern every React developer must master for production-grade data fetching.