Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

666 B
Raw Blame
import { skipToken } from '@reduxjs/toolkit/query';
import { imagesApi, useGetImageMetadataQuery } from 'services/api/endpoints/images';
import { useDebounce } from 'use-debounce';

export const useDebouncedMetadata = (imageName?: string | null) => {
  const [debouncedImageName] = useDebounce(imageName, 300);
  const { currentData: cachedData } = imagesApi.endpoints.getImageMetadata.useQueryState(imageName ?? skipToken);
  const { currentData: data, isFetching } = useGetImageMetadataQuery(debouncedImageName ?? skipToken);

  return {
    metadata: cachedData ?? data,
    isLoading: cachedData ? false : isFetching || imageName !== debouncedImageName,
  };
};