Tips for Adding a Search Feature in reactJS with the Help of MaterialUI

I have been working on creating a Pokedex using the pokeapi. The initial implementation is working well, as I am able to fetch and display Pokemon data in a container. Now, my next step is to add a search and filter functionality for the Pokemon. To achieve this, I decided to incorporate MaterialUI and include a searchBar at the top of the application.

The fetched Pokemon data is passed from App.js to my PokemonList component, which then maps the data. My current challenge is connecting the search function with the pokemonData hook in App.js to filter only the desired Pokemon before passing it to PokemonList for mapping. Any guidance on how to accomplish this would be greatly appreciated!

Below is the code snippet for my SearchAppBar component:

const SearchAppBar = () => {
const [search, setSearch] = useState("");
    console.log(search)
    return (
      <Box sx={{ flexGrow: 1 }}>
        <AppBar position="static" sx={{ bgcolor: "black"}}>
          <Toolbar>
            <IconButton
              size="large"
              edge="start"
              color="inherit"
              aria-label="open drawer"
              sx={{ mr: 2 }}
            >
              <MenuIcon />
            </IconButton>
            <Typography
              variant="h6"
              noWrap
              component="div"
              sx={{ flexGrow: 1, display: { xs:'none', sm: 'block' } }}
            >      
              <img src={logo} alt="logo" width="150" height="auto" />
            </Typography>
            <Search>
              <SearchIconWrapper>
                <SearchIcon />
              </SearchIconWrapper>
              <StyledInputBase 
                onChange={(e) => setSearch(e.target.value)}
                id='searchbox'
                placeholder="Search for Pokémon..."
                inputProps={{'aria-label': 'search'}}
              />
            </Search>
          </Toolbar>
        </AppBar>
      </Box>
    );
  }

export default SearchAppBar;

Answer №1

Store the input value in a state variable and use it to filter your data accordingly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What strategies can be used to ensure that the page layout adjusts seamlessly to even the smallest shifts in window size?

Of course, I am familiar with media queries and how they allow us to set specific min-width and max-width ranges for CSS changes. However, when I look at the website styledotme.com, I notice that the block/div beneath the navigation bar gradually shrinks ...

The functionality of angular ng-show/ng-hide is not functioning properly when used in conjunction with ng-bind-html

I am having an issue with setting ng-show or ng-hide for my elements in an HTML string and passing it to the view using ng-bind-html. Unfortunately, the ng-show/ng-hide functionality is not working as expected and my element is always visible. Below is my ...

When utilizing more than two reducers in Webpack 4, the webpackBootstrap function fails to generate

I recently updated my application to the latest versions of Webpack, React, and Redux. However, I encountered an issue where Webpack fails to generate the webpackBootstrap function when more than two reducers are added to Redux using combineReducers. While ...

What is the best way to remove the background transparency of an image?

Images are being shown inside an HTML table using PHP code : This is the code for the table : for ($i = 0; $i < $data['list']['cnt']; $i++) { $tabRows[$i][1]['width'] = "45%"; $tabRows[$i][1][&apos ...

no visible text displayed within an input-label field

Currently, I have started working on a multi-step form that is designed to be very simple and clean. However, I am facing an issue where nothing is being displayed when I click on the next arrow. I am puzzled as to why it's not even displaying the te ...

Optimizing your webpack bundle by dynamically splitting directories with the SplitChunks plugin

In an attempt to organize my React code, which was created using create-react-app, I am utilizing the splitChunks plugin in the following manner: The current structure of my components (JSX) is as follows: services serviceA ...

Tips on customizing styles for Material UI components using CSS override techniques

Currently, I am tackling a project that requires the use of Material UI components. To simplify things, let's focus on a basic functional component that includes two Material UI elements: a Button and a Text Field. import React from 'react'; ...

There seems to be an issue with Bootstrap's table-hover class causing some trouble. I could really use some assistance in resolving this

I have implemented a website with a floating reload button. Additionally, I have included a table that utilizes Bootstrap's table-hover class. However, when I hover over a row in the table, the table-hover effect highlights the row (refer to Image 1), ...

Why is the session variable in PHP failing to store the value?

Could you assist me with the following PHP code snippet? I'm trying to ensure that when the update function is called, the session variable 't' increments its value. However, every time I run the code, the output remains at Value: 1. What ad ...

Unable to set DIV width to 100% and show a scrollbar

I am facing an issue with the width of a DIV element on my webpage. Despite setting it to 100% width, it only takes up the visible window's width and not the full page width, especially when a horizontal scroll bar is displayed. Below is the HTML cod ...

Is your webpage slow to respond after a page-refresh? (Delayed HTML rendering causing lag)

Whenever I adjust the screen size to that of a phone or any device smaller than 768px, the search bar doesn't display in its proper position until the page is refreshed. It should be correctly placed right from the start. Furthermore, when I resize th ...

What is causing Next.js link to prefetch on hover every time, and how can I turn this feature off?

It appears that I am currently using the most recent version of Nextjs, which is 13.2.4v, and I am not utilizing the app or src directory. The issue arises when hovering over the Link Next component, as it triggers a server request leading to decreased per ...

Applying drop cap styles to generated content in pseudo-elements

In my blogging Q&A section, I wanted to add a unique touch by starting each question with a large question mark and each answer with a large exclamation mark as a drop cap. I tried using the ::first-letter pseudo-element along with the initial-letter prope ...

How can you add draggable functionality to a Bootstrap dropdown menu?

My custom bootstrap dropdown design <div class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> Dropdown <span cla ...

Interacting with HTML elements in Java programming

I am facing a challenging situation that requires some brainstorming. I would greatly appreciate any advice or guidance in the right direction. My goal is to incorporate a Google Map into my Java Swing project, with the map being specified as a URL wit ...

Update a div's content dynamically upon clicking using Smart content

I'm facing a challenge where I need to update the content of a div that contains Smarty tags. I have attempted the following solution, but it seems to not be working: <div>{Gbook action='form'}</div> <a id="refresh">& ...

Tips for concealing a parent element while inside a span with jquery

Beginner asking for help! Take a look at what I've coded: <div class="Links"> <a href="/testthis1.html" data-id="button1"> <img class="icon" src="/test1.png" alt="test1"> <span>Test 1</span> < ...

How can I modify the custom CSS to adjust the color of a Font Awesome icon?

Hello everyone! I am new to coding and I have a question for the Stack Overflow community. I am trying to customize the color of my Font Awesome icons on the homepage of my WordPress theme (Arcade Pro) using the custom CSS editor. Can anyone provide me w ...

Incorporating a picture backdrop into a button element in a React Typescript component

I am working on a React project with TypeScript and using a Material UI library. I am trying to set a background image for a button, but when I use src or imageURL, it gives me a TypeScript error. The CSS style also does not show the picture. Here is my ...

Adjust image loading according to screen dimensions

I am working on HTML code that currently displays an image. The code looks like this: <div> <img id="wm01" alt="PP" title="PP" u="image" src="theImages/wm01.jpg" /> </div> My goal is to show a different image based on the screen si ...