-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useFunctionQuery from documentation cause infinite loop #81
Comments
You should stringify your function before using it as query key, since react-query checks if queryKey is a function, invokes it and uses returned value as key - see https://github.com/tannerlinsley/react-query/blob/master/src/index.js#L727. IMHO using strings or tuples (as suggested in docs) is much better option, but React Query isn't limited to it and of course you are free to use it as you want. |
It's not a function, a query key is an array of function and variables [queryFn, variables]. Like I mentioned in an issue - that custom hook is take straight from react-query documentation:
|
@powah do you also use custom query key serializer? |
Oops, I guess now I understand that I have to do that. Will try and thanks for the help! |
You're welcome :) |
I liked the idea for key to use a function itself used for fetching the data because of no need to use strings or additional constants. Tried to use it from documentation and it triggers infinite rapid fetching. A function reference is stable (exported from separate module) so something inside custom hook needs to be memoized? Any guidance how to solve this?
I'm talking about this custom hook:
function useQuery(functionTuple, options) { const [queryFn] = Array.isArray(functionTuple) ? functionTuple : [functionTuple]; return useReactQuery(functionTuple, queryFn, options); }
The text was updated successfully, but these errors were encountered: