MomenSherif / react-oauth

Google OAuth2 using the new Google Identity Services SDK for React 🚀
https://www.npmjs.com/package/@react-oauth/google
MIT License
1.13k stars 141 forks source link

useGoogleLogin rerenders my component twice #354

Open dominx99 opened 4 months ago

dominx99 commented 4 months ago

I encountered odd behavior regarding the useGoogleLogin hook because only having it in my component makes it render twice.

I got a simple example:

import { Button } from "@mui/joy";
import { useGoogleLogin } from "@react-oauth/google";

export const GoogleRegisterButton = () => {
  console.log('render GoogleRegisterButton');

  const registerWithGoogle = useGoogleLogin({
    scope: 'openid email profile',
    flow: 'auth-code',
    onSuccess: res => console.log(res.code),
  });

  return (
    <Button
      onClick={registerWithGoogle}
    >
      Register with google
    </Button>
  )
}

In the console render GoogleRegisterButton appears twice.

Do you know if that is necessary for this hook? when I want to call my backend service onSuccess there are two API calls.

Without this hook, there is only one message: render GoogleRegisterButton