【发布时间】:2017-01-31 20:05:06
【问题描述】:
假设我有:
import Statement from './Statement';
import SchoolDetails from './SchoolDetails';
import AuthorizedStaff from './AuthorizedStaff';
const MultiTab = () => (
<Tabs initialIndex={1} justify="start" className="tablisty">
<Tab title="First Title" className="home">
<Statement />
</Tab>
<Tab title="Second Title" className="check">
<SchoolDetails />
</Tab>
<Tab title="Third Title" className="staff">
<AuthorizedStaff />
</Tab>
</Tabs>
);
在 Tabs 组件中,this.props 具有属性
+Children[3]
className="tablist"
justify="start"
Children[0] (this.props.children) 看起来像
$$typeof:
Symbol(react.element)
_owner:ReactCompositeComponentWrapper
_self:null
_shadowChildren:Object
_source:null
_store:Object
key:null
props:Object
ref:null
type: Tab(props, context)
__proto__
Object
Children[0].props 看起来像
+Children (one element)
className="home"
title="first title"
最后 Children 对象看起来像(这是我想要传递的):
$$typeof:Symbol(react.element)
_owner:ReactCompositeComponentWrapper
_self:null
_shadowChildren:undefined
_source:null
_store:
key:null
props:Object
__proto__:Object
**type: function Statement()**
ref:null
问题是这样的,如果我这样重写 MultiTab
<Tabs initialIndex={1} justify="start" className="tablisty">
<Tab title="First Title" className="home" pass={Statement} />
<Tab title="Second Title" className="check" pass={SchoolDetails} />
<Tab title="Third Title" className="staff" pass={AuthorizedStaff} />
</Tabs>;
标签组件内部
this.props.children 看起来和上面一样。
children[0].props 看起来像
classname:"home"
**pass: function Statement()**
title: "First title"
我希望pass 属性看起来像。上面只是打印了 Statement 函数。
$$typeof:Symbol(react.element)
_owner:ReactCompositeComponentWrapper
_self:null
_shadowChildren:undefined
_source:null
_store:
key:null
props:Object
__proto__:Object
**type: function Statement()**
ref:null
这是一个奇怪的问题,但说来话长,我正在使用一个库,这就是它的归结。
【问题讨论】:
-
为什么要将组件作为道具传递?什么时候可以导入
-
@AatifBandey 因为他传递了不同的组件?您将如何使用导入来解决这个问题?传递字符串并进行相等性检查?这没有任何意义。
标签: javascript reactjs