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:
psychedelicious 2024-03-19 21:06:57 +11:00
parent acca197893
commit e706afe8a6

View File

@ -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 };
};