src/apis/kstadiumAPI/fo/member/types.ts
export type PromiseFunc<T> = () => Promise<T>;
interface DefaultRes {
message: string;
statusCode: string;
code: number;
}
export interface ReferralRes extends DefaultRes {
data: {
userId: null | string;
referralCode: string;
};
}
// 여기서 타입을 다 지정을 해줬기 떄문에 index.ts에서 따로 타입을 지정해줄 필요가 없어진다.
export type GetReferralCode = (code: string) => Promise<ReferralRes>;
index.ts
export const getReferralCode: GetReferralCode = async (code) => {
return KStadiumInstance.get(`${SUB_URL}/referral/code/${code}`).then(
(res) => res.data,
);
};
useCheckReferralCode.ts
import { useQuery } from '@tanstack/react-query';
import KStadiumAPI from 'apis/kstadiumAPI';
const useCheckReferralCode = (code: string, isValid = false) => {
return useQuery(
[`CHECK_REFERRAL_CODE_KEY`, code, isValid],
() => KStadiumAPI.getReferralCode(code),
{
refetchOnWindowFocus: false,
enabled: !!code && isValid,
},
);
};
export default useCheckReferralCode;