mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-23 04:30:11 +09:00
25 lines
671 B
JavaScript
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
|
|
},
|
|
)
|
|
} |