Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 33x 17x 17x 17x 17x 17x | import { useQuery } from "react-query";
import { v4 as uuidv4 } from "uuid";
import type { UseQueryResult } from "react-query";
import type { Packages, Package } from "../types";
function usePackages(queryString: string): UseQueryResult<Packages, Error> {
return useQuery({
queryKey: ["data", queryString],
queryFn: async () => {
const response = await fetch(`/store.json${queryString}`);
const data: Packages = await response.json();
const packagesWithId = data.packages.map((item: Package) => {
return {
...item,
id: uuidv4(),
};
});
return {
total_items: data.total_items,
total_pages: data.total_pages,
packages: packagesWithId,
categories: data.categories,
};
},
keepPreviousData: true,
});
}
export default usePackages;
|