mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00: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:
parent
acca197893
commit
e706afe8a6
@ -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 };
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user