Files
InvokeAI/invokeai/frontend/web/src/features/nodes/hooks/useInputFieldNameSafe.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

25 lines
762 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';
export const useInputFieldNameSafe = (fieldName: string) => {
const ctx = useInvocationNodeContext();
const selector = useMemo(
() =>
createSelector(
[ctx.buildSelectInputFieldSafe(fieldName), ctx.buildSelectInputFieldTemplateSafe(fieldName)],
(fieldInstance, fieldTemplate) => {
const name = fieldInstance?.label || fieldTemplate?.title || fieldName;
return name;
}
),
[fieldName, ctx]
);
const name = useAppSelector(selector);
return name;
};