All files / app/features/profile/hooks useRegions.ts

100% Statements 12/12
100% Branches 0/0
100% Functions 4/4
100% Lines 11/11

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 304x 4x 4x   376x 376x     22x 22x   198x 198x 198x                   376x            
import { useQuery } from "@tanstack/react-query";
import { regionsKey } from "features/queryKeys";
import { service } from "service";
 
export const useRegions = () => {
  const { data, ...rest } = useQuery({
    queryKey: [regionsKey],
    queryFn: () =>
      service.resources.getRegions().then((result) =>
        result.regionsList.reduce(
          (regionsResult, { alpha3, name }) => {
            regionsResult.regions[alpha3] = name;
            regionsResult.regionsLookup[name] = alpha3;
            return regionsResult;
          },
          {
            regions: {} as { [code: string]: string },
            regionsLookup: {} as { [name: string]: string },
          },
        ),
      ),
  });
 
  return {
    regions: data?.regions,
    regionsLookup: data?.regionsLookup,
    ...rest,
  };
};