将反应组件作为道具传递
2022-08-30 02:21:07
假设我有:
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>
);
在选项卡组件中,具有属性this.props
+Children[3]
className="tablist"
justify="start"
儿童[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
儿童[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>;
选项卡组件内部
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
这是一个奇怪的问题,但长话说我正在使用一个库,这就是它归结为什么。