I have multiple places in my React app where I have code like the below, just a large switch based on a format that will load the appropriate Component. Is there a way to dynamically create the component in React? Something similar to Reflection in Java, where I could do Class.instanceOf("Rule" + this.props.selectedFormatId");
renderRules() {
switch (this.props.selectedFormatId) {
case 1:
return <Rules1 intl={this.props.intl} onRuleChange={this.props.onRuleChange}/>
case 6:
return <Rules6 intl={this.props.intl} onRuleChange={this.props.onRuleChange}/>
case 7:
return <Rules7 intl={this.props.intl} onRuleChange={this.props.onRuleChange}/>
}
}
The ultimate goal is to just keep adding new Rules to the software without having to go into each of 5 places these switches appear and update them.