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

72
Views
i want to use the Url id as a filter of an array

Im trying to put a variable in this case match.params.id into a map filter as a parameter. I want to be able to change my filter based on the URL ID return. I have put a code example bellow with some comments to further explain.

const allItems = [
{
title: item1,
itemColorBlack: 1,
itemColorWhite: 0
},
{
title: item2,
itemColorBlack: 0,
itemColorWhite: 1}
]
const itemlist = allItems.filter(
  function (item) {
    //So i want to be able with the change of the url display the itemColors.
    //In this example props.params.id returns "itemColorBlack" Url /itemColorBlack
    const itemsearch = props.match.params.id;

    //The output should only show the items where the output of itemColorBlack is 1 
    //In this case the element with the title item1. and if i change the url to 
    //itemColorWhite it should show the element with the title = item2
    return item.itemsearch == 1
   )}
.map((item) => {
  return <ItemContainer item=item />
 })

Hopefully this made sense if i need to elaborate further dont hesitate to send a message :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you need to fetch that url first , then you extract the id passed in the url via req.query store it a state variable [color,setColor]; and put your code in useEffect hook that runs when color changes ;

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!