T
TanStack4y ago
stormy-gold

useQuery with arguments?

react query question... so example from docs:
const { isLoading, isError, data, error } = useQuery('todos', fetchTodoList)
const { isLoading, isError, data, error } = useQuery('todos', fetchTodoList)
what if fetchToDoList requires params from form data? Which is my case... How am I supposed to pass fetchToDoList in this case when it requires 2 arguments that aren't accessible in the scope in my case?
3 Replies
flat-fuchsia
flat-fuchsia4y ago
Hi you should pass variable parts (arguments) in the query key which you can retrieve in your queryFn using the queryFunctionContext argument Did you manage to have something working?
flat-fuchsia
flat-fuchsia4y ago
Leveraging the Query Function Context
Use what React Query provides for optimal type safety
ambitious-aqua
ambitious-aqua4y ago
this is a great question, thanks for sharing that article @glabat!

Did you find this page helpful?