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

170
Vistas
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
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