Build a search bar in React

In this guide I am going to walk through how to make a search bar using React Hooks. There are a couple ways to do it, however the most commonly used and effective way I found to do it is by searching through an array of objects.

If you’ve seen my other posts, you’ll see that I use a similar method to include our input into the search bar.

Step 1: Create an array of objects with the useState hook

Step 2: Create a string value and array using the useState hook again and set them to empty.

  • Create a function that will handle the changes in the input field. We will add the input field into the return statement later. We will pass in an event argument.

Step 3.

  • Now we will add our JSX. I made separate files for Input and Data and added them like so, but can actually just leave all the JSX in this file if you want. For now, I’ve added this JSX code that accepts our string value and our handleChange function to check for any changes.

Step 4.

  • Create a file called Input.js and pass in an object with an argument of value and handleChange. We will be passing in our string value and handleChange function.

Step 5.

  • Now create a Data file that accepts an object with an argument called data.

Let me know if this example helped.

--

--

An aspiring software developer, hacking enthusiast, and competitive gamer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aiden Oliver

An aspiring software developer, hacking enthusiast, and competitive gamer.