[英]Props not getting passed to tabs
我有一個react-native應用程序,其中我使用React-Native-Router-Flux作為導航庫,並且在將道具傳遞給子組件時遇到了問題。 在我的login.js
文件中,用戶登錄后, login.js
使用新的路由道具(登錄的用戶名)調用新的路由。 當使用堆棧視圖時,這很好用,但對於制表符則不行,而props的值從未從其初始值更改。 我在下面列出了我的路線和登錄文件:
*未設置的道具名為Auth
登錄(為簡潔起見,減少了):
.then( (data) => {
Actions.tabbar({Auth: this.state.username})
})
路線:
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>
錯誤是我傳遞了prop的默認值,該默認值在渲染時被覆蓋。 要解決此問題,只需刪除值中的prop默認值,然后使用Action傳遞您的prop。 ,因此我從場景中刪除了Auth
屬性
解:
<routes.Scene key="tabbar" tabs={true} tabBarStyle={{ backgroundColor: '#FFFFFF' }} >
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.