File size: 889 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import { keepPreviousData, useQuery } from '@tanstack/react-query';
import apiFetch from '@wordpress/api-fetch';
import wpcomRequest, { canAccessWpcomApis } from 'wpcom-proxy-request';
import { SupportStatus } from '../types';
// Bump me to invalidate the cache.
const VERSION = 2;
interface APIFetchOptions {
global: boolean;
path: string;
}
export function useSupportStatus( enabled = true ) {
return useQuery< SupportStatus, Error >( {
queryKey: [ 'support-status', VERSION ],
queryFn: async () =>
canAccessWpcomApis()
? await wpcomRequest( { path: '/help/support-status', apiNamespace: 'wpcom/v2' } )
: await apiFetch( { path: 'help-center/support-status', global: true } as APIFetchOptions ),
enabled,
refetchOnWindowFocus: false,
placeholderData: keepPreviousData,
staleTime: 100, // 100 ms, just to prevent refreshing the data on every render.
} );
}
|