Suppose I have:
import MyComponent from "../somewhere"
I can create an instance of it by doing:
<MyComponent myprops={myprops} />
But can I create one programmatically from MyComponent
and add props?
For example, I have a list of component references:
import comp1 from "somewhere"
import comp2 from "somewhere"
import comp3 from "somewhere"
var myComponents = [
comp1, comp2, comp3
];
And now I have to take one of them and put in the view:
var randomComponent = myComponents[Math.random() * 3 | 0];
// render
render(){
return randomComponent; // this doesn't work and certain props have to be added
}
Is there a way to avoid doing the following and achieve the same?
var myComponents = [
<comp1 props=... />, <comp2 props=... />, <comp3 props=... />
];