I would like to ask, if its possible to return a component based on a variable, my idea if this is possible:
var location = this.props.location // Eg. Asia,Australia
<location+"HeaderComponent" />
My problem with this is I need to manually import all of my components individually.
This is other script that I have:
import AsiaHeaderComponent from "components/AsiaHeaderComponent.jsx";
import AustraliaHeaderComponent from "components/AustraliaHeaderComponent.jsx";
class Home extends React.Component {
renderHeader(){
if(this.props.location == "Asia"){
return (
<AsiaHeaderComponent />
);
}
else if(this.props.location == "Australia"){
return (
<AustraliaHeaderComponent />
);
}
}
render(){
return (
{ this.renderHeader() }
)
}
}
Same with above I need to manually import all of the header that will be put inside if else condition.
is there a way to efficiently do this?