Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda