File size: 1,030 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 28 29 30 31 32 33 34 35 |
import { useQuery, UseQueryResult, UseQueryOptions } from '@tanstack/react-query';
import wpcomRequest from 'wpcom-proxy-request';
import type { BlockRendererSettings } from '../types';
const useBlockRendererSettings = (
siteId: number | string,
stylesheet: string,
useInlineStyles = false,
queryOptions: Omit< UseQueryOptions< unknown, Error, BlockRendererSettings >, 'queryKey' > = {}
): UseQueryResult< BlockRendererSettings > => {
const params = new URLSearchParams( {
stylesheet,
use_inline_styles: useInlineStyles.toString(),
} );
return useQuery< any, Error, BlockRendererSettings >( {
queryKey: [ siteId, 'block-renderer', stylesheet, useInlineStyles ],
queryFn: () =>
wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteId ) }/block-renderer/settings`,
method: 'GET',
apiNamespace: 'wpcom/v2',
query: params.toString(),
} ),
...queryOptions,
staleTime: Infinity,
meta: {
persist: false,
...queryOptions.meta,
},
} );
};
export default useBlockRendererSettings;
|