@grafana/ui
Version:
Grafana Components Library
25 lines (22 loc) • 855 B
JavaScript
import * as React from 'react';
function getChildId(children) {
let inputId;
const child = React.Children.only(children);
if ("id" in (child == null ? void 0 : child.props)) {
inputId = child.props.id;
} else if ("inputId" in child.props) {
inputId = child == null ? void 0 : child.props.inputId;
}
return typeof inputId === "string" ? inputId : void 0;
}
function renderOrCallToRender(itemToRender, props) {
if (React.isValidElement(itemToRender) || typeof itemToRender === "string" || typeof itemToRender === "number") {
return itemToRender;
}
if (typeof itemToRender === "function" && props) {
return itemToRender(props);
}
throw new Error(`${itemToRender} is not a React element nor a function that returns React element`);
}
export { getChildId, renderOrCallToRender };
//# sourceMappingURL=reactUtils.mjs.map