mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-02-13 12:25:02 -05:00
- Build selectors for each node in a react context so components can re-use the same selectors - Cache the selectors in the context
21 lines
749 B
TypeScript
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);
|
|
};
|