Posts

Showing posts from April 13, 2019

React - Reference a component using a string

Image
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box; } 0 I need to call a component by using a string that is the same as the component name. Is there a way to do this without using switch or mapping the strings to the components, which I am able to do currently. I tried this, but it doesn't work, although this article uses a similar approach. render() { let CompName = 'SelectComponent'; return <CompName /> } This is just an example. The strings (component names) will be defined in an config file, which holds properties for several input fields that need to be rendered. Thanks. reactjs