From be1935306d5b14c3d86d72e8531e4aafa3ba8f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20Curley?= Date: Wed, 11 Sep 2024 11:21:33 +0100 Subject: [PATCH] docs(react-query): recommend against throwing errors in `select` Explaining why you should not thow errors in the select function Closes #8039 --- docs/framework/react/guides/render-optimizations.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/framework/react/guides/render-optimizations.md b/docs/framework/react/guides/render-optimizations.md index f50b4dfb87..2284ae76cb 100644 --- a/docs/framework/react/guides/render-optimizations.md +++ b/docs/framework/react/guides/render-optimizations.md @@ -43,6 +43,8 @@ export const useTodoCount = () => { A component using the `useTodoCount` custom hook will only re-render if the length of the todos changes. It will **not** re-render if e.g. the name of a todo changed. +> Note: `select` operates on successfully cached data and is not the appropriate place to throw errors. The source of truth for errors is the `queryFn`, and a `select` function that returns an error results in `data` being `undefined` and `isSuccess` being `true`. We recommend handling errors in the `queryFn` if you wish to have a query fail on incorrect data, or outside of the query hook if you have a error case not related to caching. + ### memoization The `select` function will only re-run if: