Download wp-calypso/client/data/home/use-home-layout-query.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/home/use-home-layout-query.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/home/use-home-layout-query.ts
-
curl -L -o use-home-layout-query.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/home/use-home-layout-query.ts
1.33 kB
| import { useQuery, UseQueryResult, QueryKey } from '@tanstack/react-query'; | |
| import wpcom from 'calypso/lib/wp'; | |
| import { useHomeLayoutQueryParams, HomeLayoutQueryParams } from './use-home-layout-query-params'; | |
| interface Options { | |
| enabled?: boolean; | |
| } | |
| const useHomeLayoutQuery = ( | |
| siteId: number | null, | |
| { enabled = true }: Options = {} | |
| ): UseQueryResult => { | |
| const query = useHomeLayoutQueryParams(); | |
| return useQuery( { | |
| queryKey: getCacheKey( siteId ), | |
| queryFn: () => fetchHomeLayout( siteId, query ), | |
| enabled: !! siteId && enabled, | |
| // The `/layout` endpoint can return a random view. Disable implicit refetches | |
| // so the view doesn't change without some user action. | |
| staleTime: Infinity, | |
| refetchInterval: false, | |
| refetchOnMount: 'always', | |
| } ); | |
| }; | |
| export function fetchHomeLayout( | |
| siteId: number | null, | |
| query: HomeLayoutQueryParams = {} | |
| ): Promise< unknown > { | |
| return wpcom.req.get( | |
| { | |
| path: `/sites/${ siteId }/home/layout`, | |
| apiNamespace: 'wpcom/v2', | |
| }, | |
| query | |
| ); | |
| } | |
| export function getCacheKey( siteId: number | null ): QueryKey { | |
| // The `dev` and `view` query params are not included in the cache key because we want all | |
| // the hooks to have the same idea of what the current view is, regardless of dev flags. | |
| return [ 'home-layout', siteId ]; | |
| } | |
| export default useHomeLayoutQuery; | |