javascript - 如何在 native react 中从其类实例化组件

标签 javascript reactjs react-native

我正在尝试在渲染中实例化一个类:

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/

相关文章:

javascript - 在 React Native 中更新 ListView

javascript - react : Cross origin requests on loading file without local server

javascript - 如何构建一个按点击计数但仅显示奇数的响应组件的答题器?

react-native - 无法识别的字体系列图标

javascript - 在React Native中将字符串转换为jsx

javascript - 嵌套组件不更新其状态

javascript - 将鼠标悬停在按钮上时如何打开 material-ui 菜单

javascript - 如何在原型(prototype)中按类选择元素?

javascript - HTML 使用带有 onkeydown 的键盘快捷键播放音频

javascript - 选择表行时启用 JSF Primefaces 设置按钮