The class receives the props.name which is the name from another Component, but it not renders properly.
class Component extends React.Component{
constructor(props){
super(props);
}
render(){
var Element = this.props.name;
return (
<Element />
)
}
}
const Dropdown = () =>{
return(
<div>
<select>
<option value="initial" selected>Select...</option>
<option value="grapefruit">Grapefruit</option>
<option value="lime">Lime</option>
<option value="coconut">Coconut</option>
</select>
</div>
)
}
class App extends React.Component {
state = {
components: []
};
render() {
return (
<div>
<Component components={this.state.components} name="Dropdown" />
</div>
);
}
}
ReactDOM.render(<App />, mountNode);
The component renders fine when I write manually the name of the Component. For example:
render(){
var Element = this.props.name;
return (
<Dropdown />
)
}
name={Dropdown}and use the same code.