Skip to content

Instantly share code, notes, and snippets.

@arnonate
Created September 23, 2020 17:39
Show Gist options
  • Save arnonate/7d3d646f894a7516b61eca9ae6088b2e to your computer and use it in GitHub Desktop.
Save arnonate/7d3d646f894a7516b61eca9ae6088b2e to your computer and use it in GitHub Desktop.
import { useQuery } from "react-query";
import axios from "axios";
export type QueryResponse = {
[key: string]: string
};
const getStuff = async (
_: string, // TODO: Figure out what this arg is
searchQuery: string,
page: number
): Promise<QueryResponse> => {
const { data } = await axios.get(
`https://fetchurl.com?query=${query}&page=${page}`
);
return data;
};
export default function useReactQuery(searchQuery: string, page: number) {
return useQuery<QueryResponse, Error>(["query", searchQuery, page], getStuff, {
enabled: searchQuery, // If we have searchQuery, enable the query on render
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment