M
M
mDrama2020-05-21 18:42:17
React
mDrama, 2020-05-21 18:42:17

What is the best way to implement the mechanics of Autocomplete search string?

Good afternoon. I thought about how best to implement autocomplete for search. The search will be performed through API requests to the server, from where the result will come.

It turns out that I need to hang onChange on the input and send requests to the server with the value of the input with each change? And then draw below the divs with the results. Isn't it too "expensive"? Well, that is, it's a bunch of API requests for each character entered.

And what is the best way to implement the div with autocomplete? Manually or are there any popular libraries for this? (For infiniti scroll, yesterday I was advised a good one here)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Didenko, 2020-05-21
@mDrama

Everything is very simple.
The usual input, when you change - you send a request, when you enter the next character - you cancel the previous request and send a new one.
You draw the results in sadzhest, display 10 pieces - there is no more sense.
No, it's not expensive.
Need a quick back up to make it look good

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question