简体   繁体   English

如何获取儿童道具

[英]How to access children's props

If I have the following structure using RNRF: 如果我使用RNRF具有以下结构:

<Scene tabs={true} tabBarComponent={()=><ScrollableTabBar items={["Approval", "My Request", " DO Customer", "My Confirm", "View Request"]}/>} tabBarPosition='top' lazy={true}>
       <Scene key="Home" hideNavBar component={Home} title={"Home"} name='Home'/>
</Scene>

How would I access name props of the child scene from within my ScrollableTabBar which is just a component passed to the parent scene? 如何从ScrollableTabBar (仅是传递给父场景的组件)中访问子场景的name道具?

I thought the children of parent <Scene> would be passed along to the component <ScrollableTabBar> , but when I tried this.props.children from ScrollableTabBar it's returning undefined. 我认为父级<Scene>将被传递到组件<ScrollableTabBar> ,但是当我尝试从ScrollableTabBar this.props.children ,它返回的是未定义的。

Thanks in advance for any pointers! 在此先感谢您提供任何指导! :) :)

My reputation is below 50 hence I couldn't post a comment. 我的声誉低于50,因此无法发表评论。

Any reason you need to have a name prop as Scene has already provided both key and title which should be sufficient 您需要name道具的任何理由,因为Scene已经提供了keytitle ,这应该足够了

Any attribute with value passed to component act as props. 任何将值传递给组件的属性都将作为道具。 So if you want to pass name too with items you can add one more attribute to ScrollableTabBar like : 因此,如果您也想通过项目传递名称,则可以向ScrollableTabBar添加另一个属性,例如:

<ScrollableTabBar items={["Approval", "My Request", " DO Customer", "My Confirm", "View Request"]} name={passValueofName}/>

You can access name like this.props.name just like you access this.props.items inside ScrollableTabBar 您可以像在ScrollableTabBar访问this.props.items一样访问诸如this.props.name类的名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM