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

144
Visualizações
How to store an html element in state

I have a component in React with a textarea that I'd like to show a button in when someone selects an option from a dropdown. Once selected I'd like the textarea to render a pill button with the value of the dropdown selection. Id like something like this photo below. enter image description here

My current solution is to have a state that gets updated with this onClick. But I am having an issue where the textarea is showing [object object] where the button for field.title should be. If i remove the button and run setTextValue(${textValue} ${field.title}) the textarea renders value just fine ex. first name, company name etc... but it just looks like the same text, The issue is that there is no styling. Is it possible to store an html element in state like this, so the value of the state has a button?

 const [textValue, setTextValue] = useState('');

<Input
  name="body" // name is used to label data being passed
  style={{ height: 150 }}
  className="border-4 rounded-0 "
  required={true}
  placeholder={"What should your customers know?"}
  type="textarea"
  rows="4"
  spellCheck="false"
  value={textValue}
  onChange={({target}) => setTextValue(target.value)}
                      />
 { fields.map(field => ( 
    <div>
     <DropdownItem onClick={(event) => setTextValue(`${textValue} ${<div><button>{field.title}</button></div>}`)} <---- this is showing [object object] when trying to render the updated state in a textarea
      <span className="d-flex justify-content-between fs--1 text-black">
       <span className="font-weight-semi-bold">{field.title}</span>
      </span>
     </DropdownItem>
    </div>
                            ))}```
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