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

298
Vistas
Display Search icon inside search box , throws error in react

I was trying to add search icon inside search box here's my code so far :

 <div className='search'>
            <input
              id="quick_search"
              className="xs-hide"
              name="quick_search"
              placeholder="Search by creator, collectible or collection."
              type="text"
              onChange={(e) => {
                changeKey(e);
              }}
              onKeyDown={keyPress}
              value={keyword} 
              >
             <i class="fa fa-search" aria-hidden="true"></i>  
              </input>
          </div>

i face this Error: input is a void element tag and must neither have children nor use dangerouslySetInnerHTML.

can anyone help me with this ? much appreciated ! thanks

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

React's input element the same as HTML's input element can't have children.

You have to make the icon appear in the input box using CSS, you can't place it as a child.

.form-field {
  position: relative;
  display: inline-block;
}

.icon {
  position: absolute;
  right: 0;
}
<div class="form-field">
  <input>
  <span class="icon">🔍</span>
</div>

Also, you didn't close the <input> tag. It's wrong because every tag in react has to be closed either by using the closing tag </input> or using a self-closing tag <input />

You code should probably look like this:

<div className='search'>
  <input
    id="quick_search"
    className="xs-hide"
    name="quick_search"
    placeholder="Search by creator, collectible or collection."
    type="text"
    onChange={(e) => {
      changeKey(e);
    }}
    onKeyDown={keyPress}
    value={keyword}
  /> {/* <--- notice `/` here */}
  <i class="fa fa-search" aria-hidden="true"></i>
</div>
about 4 years ago · Santiago Trujillo Denunciar
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