import React from "react"; import { Alert } from "react-bootstrap"; import { COMPONENTS } from './components'; export interface DynamicRendererProps { component: string | any, props: {[index: string]: any} } export interface DynamicRendererState { } class DynamicRenderer extends React.Component { constructor(props) { super(props); } public render() { console.log('HERE', this.props) if (typeof this.props.component === 'string'){ if (typeof COMPONENTS[this.props.component] !== "undefined") { return React.createElement(COMPONENTS[this.props.component],{ ...this.props.props}); } // component doesn't exist yet return (<> Componenten with id {this.props.component} not defined in COMPONENTS ); } return React.createElement(this.props.component,{ ...this.props.props}); } } export default DynamicRenderer;