{"id":16137,"date":"2023-01-12T10:33:28","date_gmt":"2023-01-12T05:03:28","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=16137"},"modified":"2026-01-16T18:26:12","modified_gmt":"2026-01-16T12:56:12","slug":"build-a-search-filter-component-in-react","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/build-a-search-filter-component-in-react\/","title":{"rendered":"Build a Search Component in React [just in 3 simple steps]"},"content":{"rendered":"\n<p>If you&#8217;re building an app that has a lot of data, whether in the form of a list or any other form, and you want the users to be able to search and get filtered results, then we need to create a way for the users to be able to find data they\u2019re searching for from the list easily. To cover this solution, adding a search and filter component to a React application can be a great way to improve the user experience by making it easier &amp; time-saving for users to find what they are looking for. In this blog post, we will discuss how to add a search and filter component to a React application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is a Search Component?<\/strong><\/h2>\n\n\n\n<p>Search bars or fields are a great way of helping users find what they need on the website. Not only this, they provide good analytics if we want to keep track of what our visitors are searching for on the website. Here we are going to use React to build a search bar that filters and displays data as the user types. With the help of React hooks and the JavaScript map and filter array methods, the result displayed is responsive with a functional search box.&nbsp;<\/p>\n\n\n\n<p>Let&#8217;s now see how a search component works in React.<\/p>\n\n\n\n<p><em>Before diving into the next section, ensure you&#8217;re solid on full-stack development essentials like <a href=\"https:\/\/www.guvi.in\/blog\/best-front-end-javascript-frameworks\/\" target=\"_blank\" rel=\"noreferrer noopener\">front-end frameworks,<\/a> back-end technologies, and <a href=\"https:\/\/www.guvi.in\/blog\/database-management-guide-with-examples\/\" target=\"_blank\" rel=\"noreferrer noopener\">database management.<\/a> If you are looking for a detailed full-stack development career program, you can join HCL GUVI\u2019s <a href=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=Build+a+Search+Component+in+React+%5Bjust+in+3+simple+steps%5D\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=Build+a+Search+Component+in+React+%5Bjust+in+3+simple+steps%5D\" target=\"_blank\" rel=\"noreferrer noopener\">full-stack development course<\/a> with Placement Assistance. You will be able to master the <a href=\"https:\/\/www.guvi.in\/blog\/guide-for-mern-stack\/\" target=\"_blank\" rel=\"noreferrer noopener\">MERN stack<\/a><\/em> <em>(MongoDB, Express.js, React, Node.js) and build real-life projects.<\/em><\/p>\n\n\n\n<p><em>Additionally, if you want to explore JavaScript through a self-paced course, try HCL GUVI\u2019s <a href=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=Build+a+Search+Component+in+React+%5Bjust+in+3+simple+steps%5D\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=Build+a+Search+Component+in+React+%5Bjust+in+3+simple+steps%5D\" target=\"_blank\" rel=\"noreferrer noopener\">JavaScript certification course.<\/a><\/em><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How does Search work in React?<\/strong><\/h2>\n\n\n\n<p>The search component in React works by allowing users to enter search terms into an input field and then filtering the results based on the search terms. This can be done by setting up an event handler for the input field to listen for changes and then using the search terms to filter the results. This can also be done with the help of JavaScript or a library like React-SearchBox, but for now, let\u2019s do this manually with the help of hooks and other things.<\/p>\n\n\n\n<p>To demonstrate how the search works in React, we\u2019ll be using the mock data to create a list provided freely by <a href=\"https:\/\/jsonplaceholder.typicode.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/jsonplaceholder.typicode.com\/<\/a> in JSON format. We are going to use the user\u2019s endpoint from that API, i.e., <a href=\"https:\/\/jsonplaceholder.typicode.com\/users\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/jsonplaceholder.typicode.com\/users<\/a>. The JSON data that comes from the API looks like below:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/tOvLU55AXIteLYWiri7lfbhfztXT47qEVMN1nrH4C4E2cWT8mnILmxhenI0DoeRkHha5KGCn6b6uXpkFZ1X72qWWlXepUjIcEc4qp868Qi0-OM44r0NfplWyyWHINEmSiQWr5qMqCxIjzLm1K0QCOso5llABZitU7oqsHSHAdaXoi6OUUr-_d1qrOdLZeQ\" alt=\"\" title=\"\"><figcaption class=\"wp-element-caption\">JSON data<\/figcaption><\/figure><\/div>\n\n\n<p>Don\u2019t get confused by the above photo; it\u2019s just an array of data displayed in JSON format. We will be using some of the data from the given array and displaying it in our React app to search and filter.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Creating a React app from scratch<\/strong><\/h2>\n\n\n\n<p>Before moving on to the steps of adding a search component, first, we need to have a React application. To create a new React application, we are going to use <strong>create-react-app <\/strong>as it is the<strong> <\/strong>best way to create a single-page application.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npx create-react-app demo\n\ncd demo\n\nnpm start<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Steps to add a Search functionality in React<\/strong><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Fetching Data<\/strong><\/h2>\n\n\n\n<p>To fetch data in React, we use the JavaScript Fetch API. It works by taking one argument and the path from where the data is to be fetched, and then returning a promise in a JSON object.<\/p>\n\n\n\n<p>In our previous blog, we have already discussed <a href=\"https:\/\/www.guvi.in\/blog\/how-to-fetch-and-display-data-from-api-in-react\/\" target=\"_blank\" rel=\"noreferrer noopener\">how to fetch and display data using API<\/a>, so we are not going to discuss that again here in detail.<\/p>\n\n\n\n<p><em>App.js file<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function App() {\n\n&nbsp;&nbsp;const url = \"https:\/\/jsonplaceholder.typicode.com\/users\";\n&nbsp;&nbsp;const &#91;data, setData] = useState(&#91;]);\n\n&nbsp;&nbsp;const fetchData = () =&gt; {\n&nbsp;&nbsp;&nbsp;&nbsp;return fetch(url)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.then((res) =&gt; res.json())\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.then((d) =&gt; setData(d));\n&nbsp;&nbsp;};\n\n&nbsp;&nbsp;useEffect(() =&gt; {\n&nbsp;&nbsp;&nbsp;&nbsp;fetchData();\n&nbsp;&nbsp;}, &#91;]);\n\n&nbsp;&nbsp;return (\n&nbsp;&nbsp;&nbsp;&nbsp;...\n&nbsp;&nbsp;);\n}\n\nexport default App;<\/code><\/pre>\n\n\n\n<p>Above, we have used the JavaScript Fetch API to fetch the data by requesting the endpoint and then storing the returned data in the data state using setData(d) and using the useEffect() hook to make the function run every time the page loads.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Displaying Data<\/strong><\/h2>\n\n\n\n<p>Now we have the data, so we are going to display it. In the App.js file, add the following code in the return() statement of the function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function App() {\n\n&nbsp;&nbsp;const url = \"https:\/\/jsonplaceholder.typicode.com\/users\";\n&nbsp;&nbsp;const &#91;data, setData] = useState(&#91;]);\n\n&nbsp;&nbsp;const fetchData = () =&gt; {\n&nbsp;&nbsp;&nbsp;&nbsp;return fetch(url)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.then((res) =&gt; res.json())\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.then((d) =&gt; setData(d));\n&nbsp;&nbsp;};\n\n&nbsp;&nbsp;useEffect(() =&gt; {\n&nbsp;&nbsp;&nbsp;&nbsp;fetchData();\n&nbsp;&nbsp;}, &#91;]);\n\n&nbsp;&nbsp;return (\n\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;center&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{data.map((dataObj) =&gt; {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div className=\"box\"&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"card\"&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"category\"&gt;@{dataObj.username} &lt;\/div&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"heading\"&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{dataObj.name}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"author\"&gt;{dataObj.email}&lt;\/div&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})}\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/center&gt;\n\n&nbsp;&nbsp;);\n\n}\n\nexport default App;<\/code><\/pre>\n\n\n\n<p>Here, we display three things: <strong>username, email, <\/strong>and<strong> name<\/strong>, from the data fetched from the users API endpoint.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Creating a Search component in React<\/strong><\/h2>\n\n\n\n<p>So, now we have created our list of data. Let\u2019s add the search component and see how the searched data is going to be returned.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Creating an Input field<\/strong><\/h3>\n\n\n\n<p>The first step is to create an input field. It allows the user to enter a search query just by typing into the search field.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div className=\"input-box\"&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; type=\"search\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; name=\"search-form\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; id=\"search-form\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; className=\"search-input\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; onChange={(e) =&gt; setSearchQuery(e.target.value)}\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; placeholder=\"Search user\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p>With the help of the<strong> onChange <\/strong>event handler, anytime the value of the input field changes, we set the value to <strong>searchQuery<\/strong> using the useState hook.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Getting search parameters<\/strong><\/h3>\n\n\n\n<p>Here, we are getting the search parameters from the data returned from the API.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const search_parameters = Object.keys(Object.assign({}, ...data));<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Function to query the search<\/strong><\/h3>\n\n\n\n<p>Next, we need to use that <b>search query<\/b> to search and filter out the data returned from our API.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const search_params = Object.keys(Object.assign({}, ...data));\n\n&nbsp;&nbsp;function search(data) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;return data.filter((data) =&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;search_params.some((param) =&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data&#91;param].toString().toLowerCase().includes(searchQuery)\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)\n\n&nbsp;&nbsp;&nbsp;&nbsp;);\n\n&nbsp;&nbsp;}<\/code><\/pre>\n\n\n\n<p>Let\u2019s understand the above function. First, we have created a function search() that takes the data as an argument. Using the Array.filter() and Array.some() methods, we are checking if any of our Search query parameters include the value of our query (searchQuery).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 4: Displaying the search results<\/strong><\/h3>\n\n\n\n<p>As the last step, we are going to use the data returned from the search(data) function to display our users list.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{search(data).map((dataObj) =&gt; {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div className=\"box\"&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"card\"&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"category\"&gt;@{dataObj.username} &lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"heading\"&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{dataObj.name}\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"author\"&gt;{dataObj.email}&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})}<\/code><\/pre>\n\n\n\n<p>And finally, your App.js file should look like below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import \".\/App.css\";\n\nimport React, { useEffect, useState } from \"react\";\n\nfunction App() {\n\n&nbsp;&nbsp;const &#91;data, setData] = useState(&#91;]);\n\n&nbsp;&nbsp;const fetchData = () =&gt; {\n\n&nbsp;&nbsp;&nbsp;&nbsp;return fetch(\"https:\/\/jsonplaceholder.typicode.com\/users\")\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.then((res) =&gt; res.json())\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.then((d) =&gt; setData(d));\n\n&nbsp;&nbsp;};\n\n&nbsp;&nbsp;useEffect(() =&gt; {\n\n&nbsp;&nbsp;&nbsp;&nbsp;fetchData();\n\n&nbsp;&nbsp;}, &#91;]);\n\n&nbsp;&nbsp;const &#91;query, setQuery] = useState(\"\");\n\n&nbsp;&nbsp;const search_parameters = Object.keys(Object.assign({}, ...data));\n\n&nbsp;&nbsp;function search(data) {\n\n&nbsp;&nbsp;&nbsp;&nbsp;return data.filter((data) =&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;search_parameters.some((parameter) =&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data&#91;parameter].toString().toLowerCase().includes(query)\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)\n\n&nbsp;&nbsp;&nbsp;&nbsp;);\n\n&nbsp;&nbsp;}\n\n&nbsp;&nbsp;return (\n\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;div className=\"container\"&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;center&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Search component in ReactJS&lt;\/h1&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/center&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div className=\"input-box\"&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type=\"search\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name=\"search-form\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id=\"search-form\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;className=\"search-input\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onChange={(e) =&gt; setQuery(e.target.value)}\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;placeholder=\"Search user\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;center&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{search(data).map((dataObj) =&gt; {\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div className=\"box\"&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"card\"&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"category\"&gt;@{dataObj.username} &lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"heading\"&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{dataObj.name}\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=\"author\"&gt;{dataObj.email}&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})}\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/center&gt;\n\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/div&gt;\n\n&nbsp;&nbsp;);\n\n}\n\nexport default App;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Output<\/strong><\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"600\" height=\"272\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/01\/ezgif.com-gif-maker-2023-01-05T135613.710.gif\" alt=\"\" class=\"wp-image-16138\" title=\"\"><figcaption class=\"wp-element-caption\">Search component in reactjs<\/figcaption><\/figure><\/div>\n\n\n<p>We often handle the search query functionality from the backend side by passing search query parameters in the API endpoint. And now we have seen how it can be handled from the front-end side.&nbsp;<\/p>\n\n\n\n<p>Now that you\u2019ve added a search component to your React application, you can easily allow your users to search for specific items or information. With a few simple steps, you can add a powerful and useful search component to your application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>In this blog, we learned how to add a search component to a React application and saw how the data is filtered from a bunch of data. The search component helps users in finding important information on the website quickly and also helps them in navigating to different pages.&nbsp;<\/p>\n\n\n\n<p><em>Kickstart your <a href=\"https:\/\/www.guvi.in\/blog\/what-is-full-stack-development\/\" target=\"_blank\" rel=\"noreferrer noopener\">Full Stack Development<\/a> journey by enrolling in <strong>HCL GUVI&#8217;s certified <\/strong><a href=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=Build+a+Search+Component+in+React+%5Bjust+in+3+simple+steps%5D\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=Build+a+Search+Component+in+React+%5Bjust+in+3+simple+steps%5D\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Full Stack Development Course<\/strong><\/a><strong> with Placement Assistance,<\/strong> where you will master the MERN stack (MongoDB, Express.js, React, Node.js) and build interesting real-life projects. This program is crafted by our team of experts to help you upskill and assist you in placements. <\/em><\/p>\n\n\n\n<p><em>Alternatively, if you want to explore JavaScript through a self-paced course, try <a href=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=Build+a+Search+Component+in+React+%5Bjust+in+3+simple+steps%5D\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/courses\/web-development\/advanced-javascript\/?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=Build+a+Search+Component+in+React+%5Bjust+in+3+simple+steps%5D\" target=\"_blank\" rel=\"noreferrer noopener\">HCL GUVI\u2019s JavaScript self-paced course.<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re building an app that has a lot of data, whether in the form of a list or any other form, and you want the users to be able to search and get filtered results, then we need to create a way for the users to be able to find data they\u2019re searching for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":72648,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[737],"tags":[804],"views":"66404","authorinfo":{"name":"GUVI Geek","url":"https:\/\/www.guvi.in\/blog\/author\/admin\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/01\/Build-a-Search-Component-in-React-300x116.webp","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2023\/01\/Build-a-Search-Component-in-React.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/16137"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=16137"}],"version-history":[{"count":24,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/16137\/revisions"}],"predecessor-version":[{"id":90187,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/16137\/revisions\/90187"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/72648"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=16137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=16137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=16137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}