最佳答案
假设我有:
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"
孩子[0](this
$$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
孩子[0]。道具看起来像
+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>;
在 Tabs 组件内部
this.props.children
看起来和上面一样。
children[0].props
看起来像
classname:"home"
**pass: function Statement()**
title: "First title"
我希望 pass
属性看起来像。上面只是打印出语句函数。
$$typeof:Symbol(react.element)
_owner:ReactCompositeComponentWrapper
_self:null
_shadowChildren:undefined
_source:null
_store:
key:null
props:Object
__proto__:Object
**type: function Statement()**
ref:null
这是一个奇怪的问题,但说来话长,我正在使用一个图书馆,这就是它归结为。