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

169
Visualizações
Why event.preventDefault() function is so important?

I have faced a problem when I create a form in react for authentication. Without using event.preventDefault() nothing has happened when I click the submitted button. But when I use this it works fine. What is the reason behind this?

here is my code

const Login = () => {
  const signinWithGoogle=(e)=>{

      e.preventDefault(); // this is my Question

      console.log('click me');
      const provider = new GoogleAuthProvider();
      signInWithPopup(auth,provider)
      .then((result)=>{
          console.log(result);
      })
      .then((error)=>{
          console.log(error);
      })
  }
  return (
      <div>
      <Form >
      <Form.Group className="mb-3 w-50 m-auto " controlId="formBasicEmail">
        <Form.Label>Email address</Form.Label>
        <Form.Control type="email" placeholder="Enter email" />
        <Form.Text className="text-muted">
          We'll never share your email with anyone else.
        </Form.Text>
      </Form.Group>
    
      <Form.Group className="mb-3 w-50 m-auto " controlId="formBasicPassword">
        <Form.Label>Password</Form.Label>
        <Form.Control type="password" placeholder="Password" />
      </Form.Group>
      <Form.Group className="mb-3 m-auto w-50" controlId="formBasicCheckbox">
        <Form.Check type="checkbox" label="Check me out" />
        <Button variant="primary" type="submit" className=''>
        Submit
        </Button>
      </Form.Group>
      <div>
      
      <button className="btn btn-primary" onClick={signinWithGoogle}>Google Signin</button>
      </div>

    </Form>
     
      </div>
  )}; 
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The default behavior of a HTML form element is to submit the contents of that form to a server, process them there, and then load a new HTML page with the result.

Since you are instead processing the form in your client-side application code, you want to prevent this default behavior, and then show the result from your JavaScript code.

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