Download wp-calypso/client/data/emails/use-get-mailboxes.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 953 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/emails/use-get-mailboxes.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/emails/use-get-mailboxes.ts
-
curl -L -o use-get-mailboxes.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/emails/use-get-mailboxes.ts
953 Bytes
| import { useQuery } from '@tanstack/react-query'; | |
| import wpcom from 'calypso/lib/wp'; | |
| import type { Mailbox } from './types'; | |
| import type { UseQueryOptions } from '@tanstack/react-query'; | |
| type UseGetMailboxesQueryData = Mailbox[]; | |
| export const getCacheKey = ( siteId: number | null ) => [ 'sites', siteId, 'emails', 'mailboxes' ]; | |
| /** | |
| * Get the associated mailboxes for a given site | |
| * @param siteId Site identifier | |
| * @param queryOptions Query options | |
| * @returns Returns the result of the `useQuery` call | |
| */ | |
| export const useGetMailboxes = ( | |
| siteId: number, | |
| queryOptions?: Omit< UseQueryOptions< any, unknown, UseGetMailboxesQueryData >, 'queryKey' > | |
| ) => { | |
| return useQuery< any, unknown, UseGetMailboxesQueryData >( { | |
| queryKey: getCacheKey( siteId ), | |
| queryFn: () => | |
| wpcom.req.get( { | |
| path: `/sites/${ siteId }/emails/mailboxes`, | |
| apiNamespace: 'wpcom/v2', | |
| } ), | |
| select: ( data ) => data.mailboxes, | |
| ...queryOptions, | |
| } ); | |
| }; | |