= ComponentType
& { + [DATA_KEY]?: DataContainer; +}; + +type ReactNodeWithData = ReactNode & { + type?: { [DATA_KEY]?: DataContainer }; +}; + +export function attachComponentData
( + component: ComponentType
, + type: string, + data: unknown, +) { + const dataComponent = component as ComponentWithData
;
+
+ let container = dataComponent[DATA_KEY];
+ if (!container) {
+ container = dataComponent[DATA_KEY] = { map: new Map() };
+ }
+
+ if (container.map.has(type)) {
+ const name = component.displayName || component.name;
+ throw new Error(
+ `Attempted to attach duplicate data "${type}" to component "${name}"`,
+ );
+ }
+
+ container.map.set(type, data);
+}
+
+export function getComponentData