Files
image-platform/apps/admin/src/infra/backend-api/hooks/use-get-asset.hook.ts

18 lines
629 B
TypeScript
Raw Normal View History

import useSWR from "swr"
import type { SWRConfiguration } from "swr"
import { backendApi } from "../client"
import type { AssetResponseDto } from "../generated/backend-api.generated"
export const getAssetKey = (publicId: string) => ["backend-api", "assets", "detail", publicId] as const
/**
* Получение asset по publicId.
*/
export const useGetAsset = (publicId: string | null, config?: SWRConfiguration) => {
const key = publicId !== null ? getAssetKey(publicId) : null
const fetcher = () => backendApi.assets.getAsset({ publicId: publicId ?? "" })
return useSWR<AssetResponseDto>(key, fetcher, config)
}