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 :)
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 ;