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

84
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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