我怎样才能将props传递给React-Native中的stackNavigator?

时间:2019-05-26 15:51:00

标签: javascript react-native

我制作了一个登录控制器组件,然后将stackNavigator传递给它,我的问题是我应该将jwt令牌传递给屏幕,但是我无法访问“ this.state.jwt”

我知道有一些熟悉的问题,但是我无法将答案笼罩在脑海中。

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)

我应该这样做:Home jwt = {this.state.jw}并针对所有其他bottomNavigator屏幕执行此操作

1 个答案:

答案 0 :(得分:0)

抱歉,评论不足,如果您将screenProps修改为

,我认为您将其作为screenProp传递
  

screenProps = {{                   jwt:this.state.jwt}}

您是否可以在屏幕上执行this.props.screenProps.jwt?