Skip to content

Commit

Permalink
feat: queries에 들어갈 fetch 훅 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jsk3342 committed Nov 14, 2024
1 parent e734991 commit 6846415
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
13 changes: 9 additions & 4 deletions frontend/src/apis/host/fetchStreamKey.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { AxiosResponse } from 'axios';
import { BASE_URL, fetchInstance } from '..';

type StreamKeyResponse = {
'stream-key': string;
'session-key': string;
};

type NanoId = string;

export const fetchStreamKey = (userId: NanoId) => {
return fetchInstance().post(`${BASE_URL}/host/key`, {
userId
});
export const fetchStreamKey = async (userId: NanoId): Promise<StreamKeyResponse> => {
const response: AxiosResponse<StreamKeyResponse> = await fetchInstance().post(`${BASE_URL}/host/key`, { userId });
return response.data;
};
24 changes: 24 additions & 0 deletions frontend/src/queries/host/useFetchStreamKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { fetchStreamKey } from '@apis/host/fetchStreamKey';
import { useMutation, UseMutationResult } from '@tanstack/react-query';

type StreamKeyResponse = {
'stream-key': string;
'session-key': string;
};

type Params = {
onSuccess?: (data: StreamKeyResponse) => void;
onError?: (error: Error) => void;
};

export default function useFetchStreamKey({ onSuccess, onError }: Params = {}): UseMutationResult<
StreamKeyResponse,
Error,
string
> {
return useMutation({
mutationFn: fetchStreamKey,
onSuccess,
onError
});
}

0 comments on commit 6846415

Please sign in to comment.