
{"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":"2023-11-29T17:19:00","modified_gmt":"2023-11-29T11:49:00","slug":"build-a-search-filter-component-in-react","status":"publish","type":"post","link":"https:\/\/guviv3.codingpuppet.com\/blog\/build-a-search-filter-component-in-react\/","title":{"rendered":"Build a Search Component in React [just in 3 simple steps]"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\"><strong>Getting Started<\/strong><\/h1>\n\n\n\n<p>If you&#8217;re building an app that has a lot of data whether in the form of a list or in 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<h1 class=\"wp-block-heading\"><strong>What is search component<\/strong><\/h1>\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 does a search component works in react.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>How does Search works in react<\/strong><\/h1>\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 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=\"\"\/><figcaption class=\"wp-element-caption\">JSON data<\/figcaption><\/figure><\/div>\n\n\n<p>Don\u2019t get confused from 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 display it in our react app for the purpose of searching and filtering.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Creating a react app from scratch<\/strong><\/h1>\n\n\n\n<p>Before moving onto 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<h1 class=\"wp-block-heading\"><strong>Steps to add a Search functionality in react<\/strong><\/h1>\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 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 an 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-data-using-api-in-react\/\" target=\"_blank\" rel=\"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 making a request to the endpoint and then storing the returned data in <strong>data<\/strong> state using <strong>setData(d)<\/strong> and used 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 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 <strong>searchQuery<\/strong> 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 <strong>Array.filter() <\/strong>and <strong>Array.some() <\/strong>methods we are checking if any of our Search query parameters include the value of our query includes(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\" loading=\"lazy\" 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\"\/><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 back end 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<h1 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h1>\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. Search component helps the users in finding the important information on the website quickly and also helps them in navigating to different pages.&nbsp;<\/p>\n\n\n\n<p>Hope you learned a lot from this blog but don\u2019t stop your learning in React.js here. Become a Full Stack Developer by joining our industry-leading project-based career program on <a href=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/\" target=\"_blank\" rel=\"noreferrer noopener\">Full Sta<\/a>ck Development offered by Zen Class which provides you with 100% job placement support, globally recognized certification, mentors support from top product based companies, and many more.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Getting Started If you&#8217;re building an app that has a lot of data whether in the form of a list or in 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 [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":16140,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[737],"tags":[804],"views":"1447","authorinfo":{"name":"Tarun Singh","url":"https:\/\/guviv3.codingpuppet.com\/blog\/author\/tarun\/"},"thumbnailURL":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-content\/uploads\/2023\/01\/How-to-add-300x169.png","jetpack_featured_media_url":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-content\/uploads\/2023\/01\/How-to-add.png","_links":{"self":[{"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/posts\/16137"}],"collection":[{"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/comments?post=16137"}],"version-history":[{"count":10,"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/posts\/16137\/revisions"}],"predecessor-version":[{"id":33660,"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/posts\/16137\/revisions\/33660"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/media\/16140"}],"wp:attachment":[{"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/media?parent=16137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/categories?post=16137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guviv3.codingpuppet.com\/blog\/wp-json\/wp\/v2\/tags?post=16137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}