@negiz/compound
Version:
A utility for creating compound components with full TypeScript type safety
12 lines (11 loc) • 511 B
JavaScript
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
function createCompound(rootComponent, childrenComponents, options = {}) {
const { displayName } = options;
const CompoundRoot = (props)=>(0, __WEBPACK_EXTERNAL_MODULE_react__.createElement)(rootComponent, props);
if (displayName) CompoundRoot.displayName = displayName;
Object.keys(childrenComponents).forEach((key)=>{
CompoundRoot[key] = childrenComponents[key];
});
return CompoundRoot;
}
export { createCompound };