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

251
Views
A bug with Reactjs OnChange and OnClick Function

Recently, I've experienced a weird bug related to ReactJS OnChange and OnClick function. Here's my code

  removeHandler(e) {
    var targetValue = e.target.getAttribute("value");
    var answerNodes = document.getElementsByClassName("answer__container");
    for (var answerNode in answerNodes) {
      if (answerNodes.hasOwnProperty(answerNode)) {
        if (answerNode === targetValue) {
          answerNodes[answerNode].remove();
        }
      }
    }
  }
  onChangeAnswers(e) {
    var answerNodes = document.getElementsByClassName("answer");
    var result = Array.from(answerNodes).map((answer) => {
    return answer.value;
    });
    this.setState({
      answers: result
    });
    console.log(this.state.answers);
  }

The interface

Particularly, when I click on remove buttons, the answer will be deleted, but after that, if I click on the answer input and press any key, the answer will disappear again. Can anyone help me solve this problem? Thanks in advance!

about 4 years ago · Juan Pablo Isaza
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!