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

188
Vistas
Second Line of Else Block Not Running

In my else block, the second line does not appear to be running. It runs setHelperText but seems to ignore setAlertValue.

  const [alertValue, setAlertValue] = useState("error");
  const [errValue, setErrorValue] = useState("Error State");
  const [helperText, setHelperText] = useState('Input "success" to remove error');

  const handleChange = (e) => {
    setErrorValue(e.target.value);

    if (e.target.value === "success") {
      setAlertValue(null);
      setHelperText("Update input to re-enable error");
    } else 
      setHelperText('Input "success" to remove error');
      setAlertValue("error"); // this line does not run
  };

  <TextField
       label="Error State"
       message="this is an ERROR message"
       alert={alertValue}
       value={errValue}
       onChange={handleChange}
       helperText={helperText}
   />
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Curly braces are missing in your code. It should be like this:

if (e.target.value === "success") {
  setAlertValue(null);
  setHelperText("Update input to re-enable error");
} else {
  setHelperText('Input "success" to remove error');
  setAlertValue("error"); 
};
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