[英]How can I pass props into stackNavigator in React-Native?
I made a login controller Component then I passed my stackNavigator into it, my problem is that I should pass jwt token into the screens but I can't access the "this.state.jwt" 我创建了一个登录控制器组件然后我将stackNavigator传递给它,我的问题是我应该将jwt令牌传递到屏幕但我无法访问“this.state.jwt”
I know there are familiar questions but I just couldn't wrap my head around the answers. 我知道有熟悉的问题,但我无法绕过答案。
export default class App extends Component {
constructor() {
super();
this.state = {
jwt: '',
loading: true
}
this.newJWT = this.newJWT.bind(this);
this.deleteJWT = deviceStorage.deleteJWT.bind(this);
this.loadJWT = deviceStorage.loadJWT.bind(this);
this.loadJWT();
}
newJWT(jwt){
this.setState({
jwt: jwt
});
}
render() {
if (this.state.loading) {
this.deleteJWT()
return (
<Loading size={'large'} />
);
} else if (!this.state.jwt) {
return (
<Auth newJWT={this.newJWT} />
);
} else if (this.state.jwt) {
return (
<RootNav screenProps={this.state.jwt} />
);
}
}
}
const BottomNaviagtor = createBottomTabNavigator ({
Home: Home,
Top: Top,
Following: {screen: Following},
LikeD: {screen:Liked}
})
const RootNav = createAppContainer(BottomNaviagtor)
Somehow I should do this: Home jwt={this.state.jw} and do this for all others bottomNavigator screens 不知怎的,我应该这样做:首页jwt = {this.state.jw}并为所有其他的bottomNavigator屏幕执行此操作
sorry not enough points to comment, i see your are passing it as a screenProp, if you modify your screenProps to 抱歉没有足够的评论点,我看到你将它作为screenProp传递,如果你修改你的screenProps
screenProps={{ jwt: this.state.jwt}}
screenProps = {{jwt:this.state.jwt}}
do you have access in your screens doing this.props.screenProps.jwt? 你有权访问你的屏幕吗?props.screenProps.jwt?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.