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

101
Views
Issue with my React state not updating properly

I'm trying to update the state of my component when a button is clicked. However, when only one of the buttons is clicked, my input state reflects an object with key input but the value is an empty array when it should be an array of the names of the buttons. This only happens when I select only one of the buttons

Here is my handleClick function:

  const [input, setInput] = useState({input: []});
  const [arr] = useState([]);

  const handleClick = async (event) => {
    event.currentTarget.classList.toggle('selected');
    if (arr.includes(event.target.getAttribute('a-key'))) {
      arr.removeByValue(event.target.getAttribute('a-key'));
    } else {
      arr.push(event.target.getAttribute('a-key'));
    }
    console.log(arr);
    setInput({input: arr});
    console.log(input);
    props.setSelected(input);
  }
about 4 years ago · Santiago Gelvez
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!