Files
InvokeAI/invokeai/frontend/web/src/features/nodes/hooks/useInputFieldUserTitleOrThrow.ts
psychedelicious 55b14c8aaf perf(ui): optimize redux selectors for workflow editor
- Build selectors for each node in a react context so components can
re-use the same selectors
- Cache the selectors in the context
2025-07-17 15:36:24 +10:00

21 lines
749 B
TypeScript

import { createSelector } from '@reduxjs/toolkit';
import { useAppSelector } from 'app/store/storeHooks';
import { useInvocationNodeContext } from 'features/nodes/components/flow/nodes/Invocation/context';
import { useMemo } from 'react';
/**
* Gets the user-defined title of an input field for a given node.
*
* If the node doesn't exist or is not an invocation node, an error is thrown.
*
* @param fieldName The name of the field
*/
export const useInputFieldUserTitleOrThrow = (fieldName: string): string => {
const ctx = useInvocationNodeContext();
const selector = useMemo(
() => createSelector(ctx.buildSelectInputFieldOrThrow(fieldName), (field) => field.label),
[ctx, fieldName]
);
return useAppSelector(selector);
};