将组件中的对象传递给React上的另一个组件

问题描述 投票:0回答:1

我已经从react-google-login登录,事实是,我需要将电子邮件从一个名为Login的组件传递到另一个名为User的组件(用户应该在其中看到他的电子邮件)。

class Login extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      email:"",
      redirecting:false,
    }
  }
render(){

      const responseGoogleSuccess = (response) => {
this.setState({email:response.profileObj.email});
        this.setState({redirecting:true});
        }
return(<div>
<GoogleLogin
    clientId="myclientid"
    buttonText="Log in"
    onSuccess={responseGoogleSuccess}
    cookiePolicy={'single_host_origin'}
  />  
{this.state.redirecting ? <Redirect to="/user" /> : null }
</div>```
I'm using reac-router-dom to redirect, so with the **Redirect** is redirecting to the URL /user where is the component **User**. If you need more details tell me. Thank you.
reactjs state router google-login prop
1个回答
0
投票

您必须将email状态移至commonLogin组件的User父级,或者使用上下文API,您可以在Doc中阅读有关此信息的信息,这是实现您所要实现的最困难的路径记住正在使用redux,这是一种状态管理

© www.soinside.com 2019 - 2024. All rights reserved.