diff --git a/src/components/Playground.jsx b/src/components/Playground.jsx index 1096881f..763e3c95 100644 --- a/src/components/Playground.jsx +++ b/src/components/Playground.jsx @@ -34,7 +34,7 @@ export default function Playground() { const fileRef = useRef(null) const queryRef = useRef(null) const [zoom, setZoom] = useState(20) - const { get, promiseGet, post, promisePost } = useAxios() + const { get, promiseGet, post, promisePost, getFetcher, postFetcher } = useAxios() const testVar = process.env.NEXT_PUBLIC_TEST const converterUrl = process.env.NEXT_PUBLIC_CONVERTER_API_URL const { getMessage } = useMessage() @@ -254,18 +254,6 @@ export default function Playground() { }) } - const getFetcher = async (url) => { - const res = await get({ url }) - console.log('🚀 ~ getFetcher ~ res:', res) - return res - } - - const postFetcher = async (url, { arg }) => { - const res = await post({ url, data: arg }) - console.log('🚀 ~ postFetcher ~ res:', res) - return res - } - const [getFetcherCallFlag, setGetFetcherCallFlag] = useState(false) const { data: tutoData, error, isLoading } = useSWR('http://localhost:8080/api/tutorial', getFetcher) const { trigger, isMutating } = useSWRMutation('http://localhost:8080/api/tutorial', postFetcher) diff --git a/src/hooks/useAxios.js b/src/hooks/useAxios.js index f2e8add9..35c90a87 100644 --- a/src/hooks/useAxios.js +++ b/src/hooks/useAxios.js @@ -95,5 +95,17 @@ export function useAxios(lang = '') { return await getInstances(url).delete(url, option) } - return { get, promiseGet, post, promisePost, put, promisePut, patch, promisePatch, del, promiseDel } + const getFetcher = async (url) => { + const res = await get({ url }) + console.log('🚀 ~ getFetcher ~ res:', res) + return res + } + + const postFetcher = async (url, { arg }) => { + const res = await post({ url, data: arg }) + console.log('🚀 ~ postFetcher ~ res:', res) + return res + } + + return { get, promiseGet, post, promisePost, put, promisePut, patch, promisePatch, del, promiseDel, getFetcher, postFetcher } }