useQuery Never Resolves Despite queryFn Executing Successfully in React 16.14.0 (TanStack Query v4.36.1) #8644
Send to my agentDescribe the bug#
I am using useQuery from TanStack Query (@tanstack/react-query v4.36.1) in a React 16.14.0 project, and I noticed that the queryFn executes successfully (I see the expected console log), but the useQuery hook never resolves or updates the React component.
Your minimal, reproducible example#
N/A
Steps to reproduce#
import { useQuery } from '@tanstack/react-query'
// Custom hook using useQuery
const useCustomQuery = useQuery<QueryResultType>({
queryKey: ['custom-query-key'],
queryFn: async () => {
const data = await fetchDataFromAPI()
console.log('async function data', data) // ✅ This logs successfully
return data
},
staleTime: 10000,
enabled: isQueryEnabled, // `isQueryEnabled` is a boolean
})
console.log('useCustomQuery', useCustomQuery) // ❌ This never logs
return useCustomQuery
Steps to Reproduce#
- Use
useQueryas shown above. - Confirm that
fetchDataFromAPI()works outsideuseQuery(it does return data). - Observe that
console.loginsidequeryFnruns, butuseQuerynever updates. - The React component does not rerender with the query result.
Expected behavior#
Expected behavior#
queryFnshould execute and return the resolved data.useQueryshould update and loguseCustomQuery.- The React component should rerender with the fetched data.
Actual behavior#
- The
queryFnexecutes successfully (I seeconsole.log('async function data', data)in the console). - However,
useQuerynever resolves or updates, andconsole.log('useCustomQuery', useCustomQuery)never logs. - The component does not receive the fetched data.
How often does this bug happen?#
None
Screenshots or Videos#
No response
Platform#
- React:
16.14.0 - TanStack Query:
4.36.1 - Browser: Firefox
134.0.2 (aarch64) - Node.js:
18.20.5
Tanstack Query adapter#
None
TanStack Query version#
4.36.1
TypeScript version#
5.6.2
Additional context#
- This issue occurs even when removing
staleTimeorenabledsettings. fetchDataFromAPI()works outsideuseQuery, so the API function itself is not the issue.- The issue persists across component re-renders.
- I suspect an issue in React Query’s cache handling or state updates.
TkDodo closed this
TkDodo added labelsneeds-info
Sign in to join this conversation.
Thank you for filing this issue, but we need more information before looking into this.
Specifically, a minimal, standalone, runnable reproduction is needed - preferably with codesandbox or stackblitz.
We'll close this issue for now, but we'll certainly re-open it if there is a proper reproduction.