【问题标题】:Pass params through switch navigator react native通过 switch navigator 传递参数 react native
【发布时间】:2020-06-17 00:55:08
【问题描述】:

我正在尝试通过切换导航器传递参数,但它目前无法正常工作。我有两个单独的堆栈导航器和一个切换导航器来在两者之间导航。第一个是登录/验证页面,另一个只是主屏幕。

我让参数通过第一个堆栈导航器(用于登录和验证),但无法将该数据获取到第二个堆栈导航器。

Verification.js -- 这里是我导航到主屏幕的地方,也是我想要传递参数的地方

    signin = async() => {
    const {state} = this.props.navigation;
    const { Name, Address, Phone, NPI } = state.params.item;

    await AsyncStorage.setItem("userToken", "user");

    this.props.navigation.navigate("App", {item: {
        Name: Name,
        Address: Address,
        Phone: Phone,
        NPI: NPI,
    }
    })
}

Homescreen.js -- 这是我想要接收这些参数的地方,但是现在 NPI 未定义并且没有参数

 writeUserData() {
        const {state} = this.props.navigation.state;
        const  NPI = state.params.item.NPI;

        const key = firebase.database().ref("/perscriptions").push().key;

        firebase.database().ref("/").child(key).set({
           surname: this.state.patientSurName,
           zip_code: this.state.zip_code,
           Sex: this.state.patientSex,
           DOB: this.state.patientDOB,
           Name: this.state.patientName,
           NPI: NPI

        })
        Alert.alert("Perscription Submitted!")


        this.reset_data()

    }

任何帮助将不胜感激!

【问题讨论】:

    标签: react-native react-navigation


    【解决方案1】:

    好的,如果有人也想知道答案,您有两种选择:

    1. 您可以通过创建一个商店然后使用您的信息更新该商店来使用 react-redux。 (可能是最好的方法)。

    2. 您可以使用 react-native 中内置的异步存储(肯定更简单,但不是最好的方法)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 2018-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多