Download wp-calypso/client/data/domains/use-get-domains-query.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 873 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/domains/use-get-domains-query.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/domains/use-get-domains-query.ts
-
curl -L -o use-get-domains-query.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/domains/use-get-domains-query.ts
873 Bytes
| import { useQuery } from '@tanstack/react-query'; | |
| import wpcom from 'calypso/lib/wp'; | |
| import type { UseQueryOptions } from '@tanstack/react-query'; | |
| import type { ResponseDomain } from 'calypso/lib/domains/types'; | |
| export const getCacheKey = ( siteId: number | null ) => [ 'sites', siteId, 'domains' ]; | |
| type UseGetDomainsQueryData = ResponseDomain[]; | |
| export const useGetDomainsQuery = ( | |
| siteId: number | null, | |
| queryOptions?: Omit< UseQueryOptions< any, unknown, UseGetDomainsQueryData >, 'queryKey' > | |
| ) => { | |
| const enabled = queryOptions?.enabled ?? true; | |
| return useQuery< any, unknown, UseGetDomainsQueryData >( { | |
| queryKey: getCacheKey( siteId ), | |
| queryFn: () => | |
| wpcom.req.get( | |
| { | |
| path: `/sites/${ siteId }/domains`, | |
| }, | |
| { apiVersion: '1.2' } | |
| ), | |
| select: ( data ) => data.domains, | |
| ...queryOptions, | |
| enabled: !! siteId && enabled, | |
| } ); | |
| }; | |