import { Gallery } from 'types/Gallery' ; import { User } from 'types/User' ; import useGet from '../_rest/useGet' ; import { GetGalleriesResponse } from './types' ; type Props = { userId : User [ 'id' ] ; } ; export const getGalleriesAction = 'fetch gallery' ; const getGalleriesBaseUrl = '/galleries/user_get' ; function getGalleriesBaseUrlWithQuery ( { userId } ) { return `${ getGalleriesBaseUrl }?user_id=${ userId }` ; } export function getGalleriesCacheKey ( { userId } ) { if ( ! userId ) { return '' ; } return [ getGalleriesBaseUrlWithQuery ( { userId } ) , getGalleriesAction ] ; } export default function useGalleries ( { userId } ) { const data = useGet < GetGalleriesResponse > ( userId ? `${ getGalleriesBaseUrlWithQuery ( { userId } ) }` : null , getGalleriesAction ) ; return data ?. galleries ; }