1

On the line:

onSuccess={() => this.responseGoogle}

How do I change this from being undefined (so that react-google-login works)?

    import GoogleLogin from 'react-google-login';

    const responseGoogle = (response) => {
      var profile = response["profileObj"];
      var email = profile["email"];
      if (email.includes('@domain.com')) {
        this.setState({ permissions: 'internal' });
      } else {
        this.setState({ permissions: 'external' });
      }
    }

  class Home extends React.Component {
    constructor(props) {
      super(props);
      this.state = { permissions: 'none' };
    }

    render(){
      return (
        <GoogleLogin
           clientID = secret
           buttonText = "Log In with Google!"
           theme = "dark"
           cookiePolicy = {'single_host_origin'}
           onSuccess = {() => this.responseGoogle}
        />
      );
    }
  }

Exact same question as React Google Login and Trouble accessing props in callback function of Google Login using react-google-login. Responses to those questions don't solve the issue (this still undefined).

Thank you very much for your thoughts!!

  • Your snippet is wrong. Can you share the exact code that's causing the error? – Dan Lupascu Jan 04 '20 at 22:16
  • @DanLupascu apologies -- found the error and added more detail. The exact error code is onSuccess = {() => this.responseGoogle}. Specifically, **this** does not bind to this.state, despite the arrow function. Rather, **this** remains undefined, causing **this.setState** to fail. Thank you very much for your thoughts. – Hide the Pain Harold Jan 05 '20 at 19:55
  • Can you share the exact code? In your snippet, the responseGoogle function is outside the Home component, why? – Dan Lupascu Jan 06 '20 at 20:03

0 Answers0