I'm looking over some older code I wrote and it seems totally different to everything in the docs now.
export const useNextLaunch = () => {
return useQuery<NextLaunch, Error>(queryKeys.nextLaunch, async ({ signal }) => {
const response = await fetch(apiEndpoints.nextLaunch, { signal });
const launch = camelCaseKeys(await response.json()) as NextLaunch;
// return stuff
});
};
Now when I look at the docs I see queryFn and queryKey everywhere and I don't understand why the API has changed this much? How would my old code look now?
useQuery({ queryKey: ['todos'], queryFn: fetchAllTodos })
useQuery({ queryKey: ['todos', todoId], queryFn: () => fetchTodoById(todoId) })
useQuery({
queryKey: ['todos', todoId],
queryFn: async () => {
const data = await fetchTodoById(todoId)
return data
},
})
useQuery({
queryKey: ['todos', todoId],
queryFn: ({ queryKey }) => fetchTodoById(queryKey[1]),
})