diff --git a/docs/framework/react/guides/query-functions.md b/docs/framework/react/guides/query-functions.md index 4fa621c697..6b4aee921d 100644 --- a/docs/framework/react/guides/query-functions.md +++ b/docs/framework/react/guides/query-functions.md @@ -5,6 +5,8 @@ title: Query Functions A query function can be literally any function that **returns a promise**. The promise that is returned should either **resolve the data** or **throw an error**. +On success, the resolved value may be anything **except `undefined`**. Queries that resolve to `undefined` will be [treated as failed](https://tanstack.com/query/latest/docs/framework/react/guides/migrating-to-react-query-4#undefined-is-an-illegal-cache-value-for-successful-queries). To store "nothing" as a successful result in the query cache, resolve `null` instead. + All of the following are valid query function configurations: [//]: # 'Example' @@ -23,6 +25,13 @@ useQuery({ queryKey: ['todos', todoId], queryFn: ({ queryKey }) => fetchTodoById(queryKey[1]), }) +useQuery({ + queryKey: ['todos', todoId], + queryFn: async () => { + const allTodosById = await fetchAllTodosById() + return allTodosById[todoId] ?? null + }, +}) ``` [//]: # 'Example'