Problem Statement
When and how would you customize the baseQuery in RTK Query?
Explanation
You customize baseQuery when you need to add authentication headers to all requests using prepareHeaders, handle token refresh logic when auth tokens expire, transform all responses or errors globally, add request interceptors for logging or analytics, or integrate with a different HTTP client like axios instead of fetch. You can wrap fetchBaseQuery with additional logic using a custom baseQuery function that calls the base query and processes results, allowing you to implement patterns like automatic retry on failure, request queuing, or global error handling. Common use cases include adding Bearer tokens from Redux state, refreshing expired tokens transparently, normalizing error responses, and adding request correlation IDs for debugging.
