📌chore: modify fetcher methods
This commit is contained in:
parent
d7e602aa70
commit
1f15734a53
@ -34,7 +34,7 @@ export default function Playground() {
|
|||||||
const fileRef = useRef(null)
|
const fileRef = useRef(null)
|
||||||
const queryRef = useRef(null)
|
const queryRef = useRef(null)
|
||||||
const [zoom, setZoom] = useState(20)
|
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 testVar = process.env.NEXT_PUBLIC_TEST
|
||||||
const converterUrl = process.env.NEXT_PUBLIC_CONVERTER_API_URL
|
const converterUrl = process.env.NEXT_PUBLIC_CONVERTER_API_URL
|
||||||
const { getMessage } = useMessage()
|
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 [getFetcherCallFlag, setGetFetcherCallFlag] = useState(false)
|
||||||
const { data: tutoData, error, isLoading } = useSWR('http://localhost:8080/api/tutorial', getFetcher)
|
const { data: tutoData, error, isLoading } = useSWR('http://localhost:8080/api/tutorial', getFetcher)
|
||||||
const { trigger, isMutating } = useSWRMutation('http://localhost:8080/api/tutorial', postFetcher)
|
const { trigger, isMutating } = useSWRMutation('http://localhost:8080/api/tutorial', postFetcher)
|
||||||
|
|||||||
@ -95,5 +95,17 @@ export function useAxios(lang = '') {
|
|||||||
return await getInstances(url).delete(url, option)
|
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 }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user