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

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