State Management · Middle · Question 62 of 75

What does the queryOptions helper give you?

export const todoQuery = (id: number) =>
  queryOptions({ queryKey: ["todo", id], queryFn: () => fetchTodo(id) });
useQuery(todoQuery(5));
queryClient.prefetchQuery(todoQuery(5));

Explanation

Keys and functions stay together, and queryClient.getQueryData(todoQuery(5).queryKey) gets the right data type automatically.

Further reading

Problem with a question

State Management · Middle · question 62

Test yourself

Take the State Management · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz