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

169
Views
React-Select Multi - Modify Hooks Array Wth Each Selection

I want to use react-select to append values to a hooks array. When I select from a selected option, I would like the item to be pushed into the hooks array, and when the user gets rid of the item, I would like the hooks array to update as well.

Here are my teams:

const teams = [
  { label: "Arsenal", value: 42 },
  { label: "Aston Villa", value: 66 },
  { label: "Brentford", value: 55 }
];

I want to put them all into a comparedTeams array hook, and update the hook onChange:

  const [comparedTeams, setComparedTeams] = useState([]);

    return (
          <div style={{ marginTop: "10px" }}>
            <Select
              isMulti
              name="select-teams"
              options={teams}
              className="basic-multi-select"
              classNamePrefix="select"
              onChange={(e) => {
                setComparedTeams([...comparedTeams, e.label]);
              }}
            />
          </div>
        );

However, whenever I add the item, I keep getting this error:

enter image description here

How do I get the hooks array to update when a user fires an onChange?

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!