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

141
Vistas
React-Select - handling changes for multiple selections and removals

I am using react-select and have the following setup below where a user is provided a report list of animal records with an "Edit" button against each record where they can assign/remove animal selections via this editable popup edit dialog.

On entry to this popup dialog, I have a useEffect hook that populates my animals array based on records edited and assigns this to the value prop within my react-select component. This is then shown correctly in my react-select select component.

At the moment, the user can see the label - "Dog".

Being a multi-select setup, my question is, when I try and select "Cat" and "Bird", my react-select component is not updating with these values and still only shows "Dog".

My question is, using the onChange, how I can reflect the new options selected within my select component as at the moment my handleChangeIndex function is not working as my optionsCopy console log is empty?

In this scenario, the end result that I am after is:

Animals assigned: Dog [x] Cat [x] Bird [x] where 'x' can be clicked to remove an entry.

const options = [
  { value: 0, label: "Dog" }, 
  { value: 1, label: 'Cat' },
  { value: 2, label: 'Bird' },
  { value: 3, label: 'Fish' }
]

const [animals, setAnimals] = useState([]);
const [selectedOptions, setSelectedOptions] = useState([]);

const handleChangeIndex = selectedOption => {
  const optionsCopy = [...selectedOptions];
  console.log("optionsCopy: ", optionsCopy)
  setSelectedOptions(optionsCopy);
};    


<Select 
   name="animal_names"
   options={options}
   isMulti={true}
   value={animals}
   onChange={(selectedOptions) => {
     handleChangeIndex(selectedOptions);
  }}                                              
/>          

 
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