2022-10-15 17:08:01 +00:00
|
|
|
export function DynamicComponent<T extends Record<string, any>>(props: {
|
|
|
|
componentMap: T;
|
|
|
|
slug: string;
|
|
|
|
wrapperClassName?: string;
|
|
|
|
}) {
|
2022-05-11 04:58:10 +00:00
|
|
|
const { componentMap, slug, ...rest } = props;
|
|
|
|
|
|
|
|
if (!componentMap[slug]) return null;
|
|
|
|
|
|
|
|
const Component = componentMap[slug];
|
|
|
|
|
2022-10-15 17:08:01 +00:00
|
|
|
return (
|
|
|
|
<div className={props.wrapperClassName || ""}>
|
|
|
|
<Component {...rest} />
|
|
|
|
</div>
|
|
|
|
);
|
2022-05-11 04:58:10 +00:00
|
|
|
}
|