Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Need help in ReactJs code - filter button

I'm trying to create a filter button by ReactJs, spent a lot of times but still do not know why it's doesn't work Here are my codePen: https://codepen.io/tinproht123/pen/gOxeWpy?editors=0110

  const [menuItems, setMenuItems] = React.useState(menu);
  const [categories, setCategories] = React.useState(allCategories);
  
  const filterItems = (category) =>{
    if(category === 'all'){
      setMenuItems(menu);
      return;
    }
    const newItems = menu.filter((item)=> item.category === category)
    setMenuItems(newItems);
  }
  
  return(
    <section className='container'>
      <div className='title'>
        <h1>Our menu</h1>
      </div>
      <Categories categories={categories} filterItems={filterItems}/>
      <Menu menu={menuItems}/>
    </section>
  )
}~~~
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I checked your code and the problem isn't in the part that you showed to us. Instead please check your codes 103th line, on codepen. Your code seems like that:

const Menu = () =>{
  return(
    <div className='menu-container'>
      {menu.map((menuItem) => {
      ....

Be careful to the first line, since your all menu items stays in menu variable, even though you made correct filtering, you're printing the result for all menus.

I saw that you're sending a prop to a <Menu menu={menuItems}>.... but you're not using it. To use this prop you should add a parameter to your Menu function;

const Menu = ({menu}) =>{
  return(
    <div className='menu-container'>
      {menu.map((menuItem) => {

Just like above.

about 4 years ago · Juan Pablo Isaza Report

0

In the Menu component, you're not passing any props but just rendering the const value declared on top of the file.

You're filtering exactly by categories but rendering is not showing the updated one. :)

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!