Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!