A. The arguments to useQuery are reversed; key should come first
B. useQuery requires a third argument for options
C. Destructuring data and isLoading is not allowed
D. fetchPosts should be a string, not a function
Solution
Step 1: Check the argument order for useQuery
The correct order is useQuery(key, fetchFunction). Here, the fetch function is passed first, then the key.
Step 2: Identify the mistake
The arguments are reversed, which will cause an error or unexpected behavior.
Final Answer:
The arguments to useQuery are reversed; key should come first -> Option A
Quick Check:
useQuery(key, fetchFn) order matters [OK]
Hint: Key always comes before fetch function in useQuery [OK]
Common Mistakes:
Swapping key and fetch function arguments
Forgetting to pass a unique key
Assuming fetch function can be a string
5. You want to fetch a list of posts and automatically refetch the data every 10 seconds using React Query. Which code snippet correctly implements this behavior?
hard
A. const { data } = useQuery('posts', fetchPosts, { staleTime: 10000 });
B. const { data } = useQuery('posts', fetchPosts, { refetchOnWindowFocus: true });
C. const { data } = useQuery('posts', fetchPosts, { cacheTime: 10000 });
D. const { data } = useQuery('posts', fetchPosts, { refetchInterval: 10000 });
Solution
Step 1: Understand refetching options in React Query
To refetch data automatically at intervals, use the refetchInterval option with the interval time in milliseconds.
Step 2: Match the correct option
const { data } = useQuery('posts', fetchPosts, { refetchInterval: 10000 }); uses refetchInterval: 10000 which means refetch every 10 seconds. Other options control different behaviors.
Final Answer:
const { data } = useQuery('posts', fetchPosts, { refetchInterval: 10000 }); -> Option D
Quick Check:
Auto refetch = refetchInterval option [OK]
Hint: Use refetchInterval to auto-refresh data periodically [OK]
Common Mistakes:
Confusing refetchOnWindowFocus with interval refetch
Using cacheTime or staleTime incorrectly
Not passing options as third argument
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.