gpt-4.1-2025-04-14· OpenAI
LMArena Human Preference 140K
Would useSuspenseQuery hook from react-query have ever return isFetched value as false?
- User
Would useSuspenseQuery hook from react-query have ever return isFetched value as false?
- Assistant
Great question! Let's clarify how the
useSuspenseQueryhook from React Query (now called TanStack Query) works, especially regarding theisFetchedvalue.Key Points
useSuspenseQueryis a special hook that enables React Suspense for data fetching.- When using
useSuspenseQuery, the component will suspend rendering until the data is fetched (or an error occurs). - The hook does not return any loading state (
isLoading,isFetching, etc.) because the component is suspended during loading.
About
isFetchedisFetchedis a boolean that indicates whether the query has been successfully fetched at least once.- In the context of
useSuspenseQuery, the hook will only return when the data is available (i.e., after fetching is complete). - Therefore,
isFetchedwill always betruewhen the hook returns, because the component would not render until the data is fetched.
Example
const { data, isFetched } = useSuspenseQuery(['todos'], fetchTodos); // At this point, isFetched is always trueWhy?
- If the data is not yet fetched, the hook will throw a Promise, suspending the component.
- Only after the data is fetched (or an error occurs), the component will resume rendering, and the hook will return the result.
- So,
isFetchedwill never befalsewhen usinguseSuspenseQuery.
Summary Table
Hook Can isFetchedbefalse?useQueryYes useSuspenseQueryNo
References
In summary:
useSuspenseQuerywill never returnisFetchedasfalse. It will always betruewhen the hook returns, because the component is suspended until the data is fetched.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.