0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-12-23 04:30:11 +09:00
yude.jp/pages/lib/useRequest.js
2021-05-28 10:42:42 +09:00

25 lines
671 B
JavaScript

import useSWR from 'swr'
import axios from 'axios'
export default function useRequest(request, { initialData, ...config } = {}) {
return useSWR(
request && JSON.stringify(request),
() => axios(request || {}).then(response => response.data),
{
...config,
initialData: initialData && {
status: 200,
statusText: 'InitialData',
headers: {},
data: initialData
},
revalidateOnFocus: false,
revalidateOnMount:false,
revalidateOnReconnect: false,
refreshWhenOffline: false,
refreshWhenHidden: false,
refreshInterval: 0,
shouldRetryOnError: false
},
)
}