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

104
Visualizações
Form needs to be submitted twice

I am trying to implement a super simple, super primitive authentication page for my website. The user sees just a single input field and a submit button. If the input matches the password (hashing remains to be added) the user is authenticated.

The problem is, however, that you always have to input the correct string and press the submit button twice. I don't know why this is happening, and it is obviously quite annoying.

Is there any solution for this? All I've found is to use e.preventDefault(), which I am already using, but to no avail.

import { useState } from 'react'
import App from '../App'

export default function Password() {
  const [auth, setAuth] = useState(false)
  const [pass, setPass] = useState("")
  const secret = ""

  const handleChange = e => {
    setPass(e.target.value)
  }

  const handleSubmit = e => {
    e.preventDefault()
    e.nativeEvent.stopImmediatePropagation();
    if (pass === secret) {
      setAuth(true)
    }
  }

  if (auth) {
    return (
      <App/>
    )
  } else {
    return (
      <form onSubmit={handleSubmit}>
        <input style={{ border: "1px solid grey", borderRadius: "4px" }} type="text" value={pass} onChange={handleChange} />
        <input style={{ border: "1px solid grey", borderRadius: "4px" }} type="submit" value="submit" />
      </form>
    )
  }
  
}
about 4 years ago · Juan Pablo Isaza
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