Files
InvokeAI/invokeai/frontend/web/src/services/api/hooks/useDebouncedImageWorkflow.ts
psychedelicious 89ff9b8b88 perf(ui): optimize all selectors 2
Mostly selector optimization. Still a few places to tidy up but I'll get to that later.
2024-09-06 22:56:24 +10:00

17 lines
730 B
TypeScript

import { skipToken } from '@reduxjs/toolkit/query';
import { useAppSelector } from 'app/store/storeHooks';
import { selectWorkflowFetchDebounce } from 'features/system/store/configSlice';
import { useGetImageWorkflowQuery } from 'services/api/endpoints/images';
import type { ImageDTO } from 'services/api/types';
import { useDebounce } from 'use-debounce';
export const useDebouncedImageWorkflow = (imageDTO?: ImageDTO | null) => {
const workflowFetchDebounce = useAppSelector(selectWorkflowFetchDebounce);
const [debouncedImageName] = useDebounce(imageDTO?.has_workflow ? imageDTO.image_name : null, workflowFetchDebounce);
const result = useGetImageWorkflowQuery(debouncedImageName ?? skipToken);
return result;
};