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

70
Vistas
how to reset input fild without empty string in react.js

How can I reset the input field if I use it this way?

const [email, setEmail] = useState({ email: "", emailError: "" });
   
    const handleEmail = (inputEmail) => {
    if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(inputEmail)) {
      setEmail({ email: inputEmail, emailError: "" });
    } else {
      setEmail({ email: "", emailError: "Invalid Email" });
    }
  };

   <Form.Control type="email"  onChange={(e) => handleEmail(e.target.value)} name="email" 
    placeholder="Enter email" />
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use initial state variable, this is one of the best approach to reset states in react. If you want to reset seperately then you can give initial values for email and emailError instead of giving whole initial object

const initialState = {
    email: "",
    emailError: ""
}

const [email, setEmail] = useState(initialState);
    
const reset = () => {
  setEmail(initialState)
}
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