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

85
Vistas
converting js into react autocomplete search input form

quite new to this react thing but i previously wrote a simple js script for my own search input for autocomplete

$(function () {
    $("#search_item").autocomplete({
        minLength: 1,
        source: function (req, resp) {
            var collected;
            $.getJSON("https://api.test.com/items/autocomplete?q=" + req.term, function (json) {
                console.log(json);
                resp(json.data);
            })
        }
    });
});

html

 <form action="/api/search">
                <div class="input-group">
                    <input id="search_item" type="text" class="form-control" placeholder="Search for..." name="item_search_keyword">
                    <span class="input-group-btn">
                        <button class="btn btn-secondary" type="submit" id="btnSubmit">Search!</button>
                    </span>
                </div>
            </form>

trying to convert this into React with a simple input search bar but not so familiar with React. Possible if anyone can give me some help?

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

0

I think the best answer to this is that you need to convert your mind to React first, before converting the code.

It is not just a small change to migrate code like that to React. React follows a fundamentally different approach, which is not compatible with your example. E.g. you should not touch the DOM directly.

Imagine you are not writing javascript / DOM anymore, but you are writing a different language (i.e. React) now.

As a vague direction for a solution: I guess you would create a React component like <MyInputWithAutoComplete>, which returns e.g. your input-group, and handles your autocomplete logic with a useEffect.

about 4 years ago · Santiago Gelvez 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