Created
September 23, 2020 17:39
-
-
Save arnonate/7d3d646f894a7516b61eca9ae6088b2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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