我正在尝试在渲染中实例化一个类:
import myFirstComponentfrom './components/myFirstComponentfrom'
import mySecondComponent'./components/mySecondComponent'
additionalComponents= [
{component:myFirstComponent},
{component:mySecondComponent}
]
...
render(){
return (
<View>
{additonalComponents[0].component}
{additonalComponents[1].component}
</View>
}
不幸的是,它不起作用......知道如何做到这一点吗?
谢谢
最佳答案
找到答案,使用:
render(){
return (
<View>
{React.createElement(this.additionalComponents[0].component, {})}
{React.createElement(this.additionalComponents[0].component, {})}
</View>
}
关于javascript - 如何在 native react 中从其类实例化组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46872960/