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

190
Visualizações
Passing useState value to React input component

I have created a React component that allows the user to filter a list by typing into an input, I have simplified the component into the below:

const value = filteredOptions
   .filter((option) => option.selected)
   .map((option) => option.label)
   .join(",");

const [input, setInput] = useState(value);

const handleSearch = (e) => {
   e.preventDefault();
   setInput(e.target.value);
};

return (
<InputSearch 
   value={input}
   onChange={handleSearch}
/>
<SelectOption
   key={option.code}
   option={option}
   onClick={onValueChange}
/>

);

value is null by default (and is populated with a string value when selected) - this works. what I would like to do however is feed the value into my input state so that the input state can be updated either by typing into the input (which works currently) or by selecting a value.

about 4 years ago · Juan Pablo Isaza
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