Autocomplete Input in React

javascript react autocomplete input data feching
Autocomplete Input in React


This is the first lab in the series of cool React mini apps/components that we are going to build together. I have tried to keep it simple and at the same time informative enough so that you folks actually learn about how to create a custom autocomplete input box in React.

Features of the component

  1. There is an input box with placeholder
  2. On focussing on the input, a list of pokemons with their name and image appear in the div below.
  3. You can type something in the input and the list will get filtered accordingly
  4. On selecting an item in the list, the list disappears with the name of the pokemon in the input.
  5. Nice to have features:
    1. If the list of pokemons is visible, clicking on the input or any where in the page, the list should disappear and should reappear again when focussing on the input


Learning Objectives

In this lab, you will learn about different React concepts like hooks, creating a function component, data fetching in React, usage of array functions like map, fill, filter, etc.


To get the most out of this series:

You need to be at least acquainted with basic JS and React concepts. You will be able to understand everything if you have given atleast a day to learn React.


Code/Environment Setup:

Preferred Code Editor: VS Code,

Node version >= 12.0.0

Create a react project boilerplate using the create-react-app CLI or if you have npx installed on your system you can directly do npx create-react-app

To get npx on your system, run

npm install -g npx
npx create-react-app custom-autocomplete-react
cd custom-autocomplete-react
yarn start or npm start

and there you go!

You have your react project ready to be consumed and altered into something meaningful.

Next Steps!

Well, here we are now, ready with our custom autocomplete input. This is just a start. In the next lab, we will tweak this project up a little.

We will try to make debounced network calls while typing text inside our input. Try to learn about debouncing

Further on this in the next lab.

🚀 If you liked ❤️ the content 📜, do hit the LIKE 👍 button and FOLLOW ✅ me for interesting content ahead ✨.

Stay tuned!