【问题标题】:TabContent in react-bootstrap & componentClass propsreact-bootstrap 和 componentClass 道具中的 TabContent
【发布时间】:2017-03-05 16:29:54
【问题描述】:

我正在尝试将一个反应组件传递给 TabContents componentClass 道具。这个反应组件还需要添加道具。我只是想知道这怎么可能。

我尝试了一些类似的东西

import MyClass from './somewhere';
import { TabContent } from 'react-bootstrap';
const x = <MyClass thing={y} />
..
..
<TabContent componentClass={x} /> 

但它似乎不起作用 TabContent 类的 componentClass propType 需要元素或字符串。我想知道将需要不是纯组件的道具的反应组件传递给选项卡窗格的最佳方法是什么...

仅供参考。我想传入的这个组件从装载时的 API 或类似的东西中获取数据。

【问题讨论】:

  • 所以您不想在TabContent 中渲染MyClass?你想达到什么目的?
  • 我正在尝试在Tab 内渲染MyClass,这意味着我需要使用TabContent,并且react-bootstrap 文档暗示我需要将MyClass 传递到TabContent 的componentClass道具

标签: reactjs ecmascript-6 react-bootstrap


【解决方案1】:

MyClass 将继承 TabContainer 的所有属性。因此,您可以按原样传入组件并在TabContainer 上设置您想要的道具。

import MyClass from './somewhere';
import { TabContent } from 'react-bootstrap';
..
..
<TabContent componentClass={MyClass} thing={y} /> 
// MyClass will have `this.props.thing`.

【讨论】:

    猜你喜欢
    • 2016-09-23
    • 2019-11-19
    • 2019-10-03
    • 2021-05-08
    • 2016-07-28
    • 2020-06-13
    • 2017-04-23
    • 1970-01-01
    • 2020-11-17
    相关资源
    最近更新 更多