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 284x 4x 4x   4x 70x 17x 17x   153x 153x 153x                   70x            
import { regionsKey } from "features/queryKeys";
import { useQuery } from "react-query";
import { service } from "service";
 
export const useRegions = () => {
  const { data, ...rest } = useQuery(regionsKey, () =>
    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,
  };
};