stylist / frontend / src / api / useFetchSalonPage.ts
useFetchSalonPage.ts
Raw
import { QueryOptions, useQuery } from 'react-query';

import { api } from '.';
//types
import { SalonPage } from '@/types/salon';

const fetchSalonPage = async (id: number | undefined) => {
  if (!id) {
    return undefined;
  }
  return await api.get<never, SalonPage>(`/salons/${id}`);
};

export const useFetchSalonPage = (
  id: number | undefined,
  options?: QueryOptions<SalonPage | undefined>
) => {
  return useQuery(['salons', id], () => fetchSalonPage(id), options);
};