Cannot create an element in react component dynamically

From the createElement documentation:

Create and return a new React element of the given type. The type argument can be either a tag name string (such as 'div' or 'span'), a React component type (a class or a function), or a React fragment type.

You are trying to use a React component type therefore you cannot use a string, you need to use the class directly:

const GraphWidget = React.createElement(PieChart);

If your aim is to map strings to components, you can create simple mapping using a dictionary:

const components = {
    PieChart: PieChart
    ...
};

const GraphWidget = React.createElement(components['PieChart']); 

Tags:

Reactjs