简体   繁体   English

道具不传递到选项卡

[英]Props not getting passed to tabs

I have a react-native app where I'm using React-Native-Router-Flux as my navigation library, and I'm having an issue with the props being passed down to the children components. 我有一个react-native应用程序,其中我使用React-Native-Router-Flux作为导航库,并且在将道具传递给子组件时遇到了问题。 In my login.js file, after a user logs in, a new route is called with the new route props (the logged in username) as well. 在我的login.js文件中,用户登录后, login.js使用新的路由道具(登录的用户名)调用新的路由。 This works fine when using a stack view, but not for tabs, whereas the props value never changed from it's inital value. 当使用堆栈视图时,这很好用,但对于制表符则不行,而props的值从未从其初始值更改。 I've listed my Routes and login file below: 我在下面列出了我的路线和登录文件:

*The prop not being set is named Auth *未设置的道具名为Auth

login (reduced for brevity): 登录(为简洁起见,减少了):

.then( (data) => {
          Actions.tabbar({Auth: this.state.username})
        })

routes: 路线:

  render() {
    return (
      /* Start Router */
      <routes.Router>
        {/* Start Root Stack */}
        <routes.Scene key="root" headerMode = "none"  hideNavBar={true} tabBarPosition="bottom" >

          {/* Home Route as a stack */}
          <routes.Scene key="Home Test"  title="Home">
              <routes.Scene  key="Home Test"  component={Home} title="Home" />
          </routes.Scene>

          {/* Signup Screen as a Stack */}
          <routes.Scene key="SignupScreen" title="Signup Screen">
            <routes.Scene key="SignupScreen"  component={SignupScreen} title="SignupScreen" />
          </routes.Scene>

          {/* Start Tabs view */}
          <routes.Scene key="tabbar" tabs={true} Auth = {null} tabBarStyle={{ backgroundColor: '#FFFFFF' }}  >

            {/* Live Feed Tab View */}
            <routes.Scene key = "live" title = "live">
              <routes.Scene key="LiveFeed" component={LiveFeed} title="LiveFeed" userLoggedIn = {null} />
            </routes.Scene>

            {/* User Directory Tab View */}
            <routes.Scene key = "User Directory" title = "User Directory">
              <routes.Scene key="UserDirectory" component={UserDirectory} title="UserDirectory" />
            </routes.Scene>

           {/* Messages Tab View */}
           <routes.Scene key = "Messages" title = "Messages">
             <routes.Scene key="Messages" component={Messages} title="Messages" userLoggedIn = {this.props.Auth} />
             <routes.Scene key="Message" component={Message} title="Message" userLoggedIn = {null} ThreadRequested =  {null} />
           </routes.Scene>

          {/* End Tabs View */}
          </routes.Scene>
          {/* End Root Stack */}
        </routes.Scene>
        {/* End Router */}
      </routes.Router>

The error was I was passing the default value of the prop, which was overwriting it when rendered. 错误是我传递了prop的默认值,该默认值在渲染时被覆盖。 To fix, just remove the prop default value within the value, and pass down your props with Action. 要解决此问题,只需删除值中的prop默认值,然后使用Action传递您的prop。 , thus I removed the Auth property from the scene ,因此我从场景中删除了Auth属性

Solution: 解:

   <routes.Scene key="tabbar" tabs={true} tabBarStyle={{ backgroundColor: '#FFFFFF' }}  >

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

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