我已经从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.
您必须将email
状态移至common
和Login
组件的User
父级,或者使用上下文API,您可以在Doc中阅读有关此信息的信息,这是实现您所要实现的最困难的路径记住正在使用redux,这是一种状态管理