Ad

How To Make Correctly Autocomplete In React

- 1 answer

I want to make autocomplete input of cities in React. I have json file of cities ~15mb. How should I correctly implement it? Should I keep this json on client side?

Ad

Answer

you could make a request to the server on every keystroke but start the search after say 3 characters

e.g. searching for London

You would only make the first request after the user has typed in Lon

15mb seems a lot though, maybe you want to think of filtering this down beforehand so you request less countries back. e.g. make the user select a country beforehand so you only request cities in that country. so if they pick USA, then type in Chi it would only return cities in the USA starting with Chi

I don't think it's a good idea to pull the 15mb client side as that is a huge amount of data

Ad
source: stackoverflow.com
Ad