Conditional prefetching with usePrefetchQuery #7713
-
The addition of As an example: const isFooEnabled = useFeatureFlag('foo_enabled')
usePrefetchQuery({
queryKey: ...
queryFn: ...,
enabled: isFooEnabled
}) Is this something we could support? |
Beta Was this translation helpful? Give feedback.
Answered by
TkDodo
Jul 26, 2024
Replies: 1 comment 5 replies
-
why would you need conditional prefetching? The better idea would be to move it to a component that gets conditionally rendered. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if we add enabled, it wouldn't have the same signature as on
useQuery
because we can't make it a function because we don't have a query instance yet. I think your case is rare enough to not include it, you can always copy the hooks implementation (it's 3 lines of code) and add an if statement yourself, of create a component that you can render conditionally that calls the hook and returns null.