import { UseQueryOptions, UseQueryResult, keepPreviousData, useQuery } from "@tanstack/react-query";

import { TDataSourceError, TDataSourceRecord } from "./types";

export const useOne = <
  TQueryFnData extends TDataSourceRecord = TDataSourceRecord,
  TError = TDataSourceError,
  TData extends TDataSourceRecord = TQueryFnData
>(
  options: UseQueryOptions<TQueryFnData, TError, TData>
): UseQueryResult<TData, TError> => {
  return useQuery<TQueryFnData, TError, TData>({
    placeholderData: keepPreviousData,
    ...options,
  });
};
