Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何将数据从一个屏幕发送到TabNavigator_Reactjs_React Native_React Navigation - Fatal编程技术网

Reactjs 如何将数据从一个屏幕发送到TabNavigator

Reactjs 如何将数据从一个屏幕发送到TabNavigator,reactjs,react-native,react-navigation,Reactjs,React Native,React Navigation,我有一个带有2个输入(电子邮件和密码)的登录屏幕,如果登录正确,我想向TabNavigator this.props.navigation.navigate("Profile", { email: email }) 我想像这样接收这个参数 const email=navigation.getParam('email') 但不幸的是,它不起作用。/*-----------在state中定义“name”---------*/ /* --------- Define 'name' in sta

我有一个带有2个输入(电子邮件和密码)的登录屏幕,如果登录正确,我想向
TabNavigator

this.props.navigation.navigate("Profile", {
   email: email
})
我想像这样接收这个参数

const email=navigation.getParam('email')

但不幸的是,它不起作用。

/*-----------在state中定义“name”---------*/
/* --------- Define 'name' in state ---------*/

state = {
    name: ''
}

/*------- if you will get success response then write this  -------*/

LoginAPICall = () => {
    fetch(‘URL’, {
        method: 'POST',
            headers: {
            'Accept': 'application/json',
                'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            Email: this.state.email,
            Password: this.state.password
        })
    }).then((response) => response.json())
        .then((responseJson) => {
            if(responseJson.statuscode == 1) {
                this.props.navigation.navigate(‘Login’,{
                    NAME : responseJson['data']['user'].name
                });
                alert("Check your email for a password reset link!");
            } else {
                Alert.alert(responseJson.message);
            }
        }).catch((error) => {
            console.error(error);
        });
}


/*--------- in next activity controller write below lines ---------*/

constructor(){
    super();
    this.state = {
        User_Name : '',
    }
}

componentDidMount(){
    this.setState({
        User_Name: this.props.navigation.state.params.NAME,
    })
}

render () {
    alert (this.state.User_Name);
    return (
        <View>
            <Text>Hello</Text>
        </View>
    );
}
状态={ 名称:“” } /*-------如果你会得到成功的回应,那么写下这个-------*/ LoginAPICall=()=>{ 获取('URL'{ 方法:“POST”, 标题:{ “接受”:“应用程序/json”, “内容类型”:“应用程序/json”, }, 正文:JSON.stringify({ 电子邮件:this.state.Email, 密码:this.state.Password }) }).then((response)=>response.json()) .然后((responseJson)=>{ if(responseJson.statuscode==1){ this.props.navigation.navigate('Login'{ 名称:responseJson['data']['user'].名称 }); 警报(“检查您的电子邮件中的密码重置链接!”); }否则{ Alert.Alert(responseJson.message); } }).catch((错误)=>{ 控制台错误(error); }); } /*---------在下一个活动控制器中,写下以下几行---------*/ 构造函数(){ 超级(); 此.state={ 用户名:“”, } } componentDidMount(){ 这是我的国家({ 用户名:this.props.navigation.state.params.Name, }) } 渲染(){ 警报(此.state.User\u名称); 返回( 你好 ); }
您是否阅读了文档?您使用的是哪种版本的react导航?