mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-02-03 00:25:24 -05:00
feat(ui): add valueOrNull to useMetadataItem
In order to allow for null and undefined metadata values, this hook returned a symbol to indicate that parsing failed or was pending. For values where the parsed value will never be null or undefined, it is useful get the value or null (instead of a symbol).
This commit is contained in:
@@ -72,5 +72,12 @@ export const useMetadataItem = <T,>(metadata: unknown, handlers: MetadataHandler
|
||||
handlers.recall(value, true);
|
||||
}, [handlers, value]);
|
||||
|
||||
return { label, isDisabled, value, renderedValue, onRecall };
|
||||
const valueOrNull = useMemo(() => {
|
||||
if (value === MetadataParsePendingToken || value === MetadataParseFailedToken) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}, [value]);
|
||||
|
||||
return { label, isDisabled, value, renderedValue, onRecall, valueOrNull };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user