-
I am attempting to create a default query function that accesses the GitHub API and uses the import "@/styles/globals.css";
import type { AppProps } from "next/app";
import { QueryClient, QueryClientProvider } from "react-query";
const queryGithubOrginisation = ({ queryKey <--- What type? }) => {
const BASE_URL = `https://api.github.com/`;
let queryParams = "";
if (typeof queryKey[queryKey.length - 1] === "object") {
const paramsObject = queryKey.pop();
queryParams = "?" + new URLSearchParams(paramsObject).toString();
}
const apiPath = queryKey.join("/");
const requestUrl = `${BASE_URL}${apiPath}${queryParams}`;
return fetch(requestUrl).then((res) => res.json());
};
export default function App({ Component, pageProps }: AppProps) {
const queryClient = new QueryClient({
defaultOptions: {
queries: {
queryFn: queryGithubOrginisation,
},
},
});
return (
<QueryClientProvider client={queryClient}>
<Component {...pageProps} />
</QueryClientProvider>
);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can use the type
the |
Beta Was this translation helpful? Give feedback.
You can use the type
QueryFunctionContext
to type the whole object:the
queryKey
itself will be of typeQueryKey
.