Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

335
Visualizações
Warning: Cannot update a component (`BrowserRouter`) while rendering a different component (`FormSocialIcon`)

I am getting warning [ Cannot update a component (BrowserRouter) while rendering a different component (FormSocialIcon).] while login.How to solve this warning?

FormSocialIcon component

const FormSocialIcon = () => {
const [signInWithGoogle, user, loading, error] = useSignInWithGoogle(auth);

const navigate = useNavigate();
let location = useLocation();

let from = location.state?.from?.pathname || "/";

let errorMessage;
if (error) {
    errorMessage =
        <div>
            <p className='text-red-500 font-bold'>Error: {error.message}</p>
        </div>
}
if (loading) {
    return <Loader></Loader>
}

if (user) {
    navigate(from, { replace: true });
}

return (
    <div>
        <div className='flex justify-center items-center mt-3'>
            <div className='bg-indigo-600 w-60 h-0.5'></div>
            <div className='mx-2 font-semibold'>Or</div>
            <div className='bg-indigo-600 w-60 h-0.5'></div>
        </div>
        <div>
            {errorMessage}
            <button onClick={() => signInWithGoogle()} className='w-full md:w-96 flex justify-center mt-5 mx-auto p-2 border-2 border-indigo-500 rounded font-semibold outline-none hover:font-bold hover:transition-all hover:scale-110'>Continue with google<img className='w-5 ml-2' src={googleIcon} alt="" /></button>
        </div>
    </div>
);

};

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

0

It has to be wrapped in an effect so that it runs after it rendered, not during the render phase.

function  MyComponent() {
  
  React.useEffect(() => {
    if (accessToken) {
        navigate(from, { replace: true });
    }
    
  }, [])
  
  
  return (<div>{/* ... */}</div>)
  
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda