📌chore: modify fetcher methods

This commit is contained in:
yoosangwook 2025-01-15 14:26:42 +09:00
parent d7e602aa70
commit 1f15734a53
2 changed files with 14 additions and 14 deletions

View File

@ -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)

View File

@ -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 }
}