Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
Select Dropdown not Passing Selected Values to Array in React

I am building a dropdown menu in React using a select dropdown.

or some reason, my selected value is not passing, it is passing the entire array instead of the value I selected on the dropdown.

What am I doing wrong here and how can I pass the value that I selected via dropdown?

Dropdown Code in React

  <select
                className='add-cap-select'
                onChange={(value) => handleChangeForm('agent', value)}
              >
                {agents.map((agent) => (
                  <option id='agent' key={agent} value={form.agent}>
                    {agent}
                  </option>
                ))}
              </select>

      /**
   * Handles when the user changes any regular form entry
   * @param {String} prop
   * @param {String} value
   */
  const handleChangeForm = (prop, value) => {
    setForm({
      ...form,
      [prop]: value
    })
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here is my simple solution to do this

import React, {useState} from 'react';

export function App(props) {
  const [agent, setAgent] = useState({
    agent:'',
  });
  const handleChangeForm = event =>{
    console.log(event.target.name, event.target.value)
    setAgent({...agent,[event.target.name]:event.target.value})
  }

  return (
    <select
                className='add-cap-select'
                name="agent"
                onChange={(event) => handleChangeForm(event)}
              >
               <option value="one">one</option>
               <option value="two">two</option>
               <option value="three">three</option>
              </select>
  );
}

you are passing agent and value both in handleFormChange, instead of this you can put the name in select, and from the event, you can get the name as well as value, here you are directly passing value which is event actually if you want to do in your solution then you can do like this -> value.target.value

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda