last day (15 days later) » 

4:37 PM
0
Q: in ReactJS, how can i filter the rendered result according to an id number passed in the props

Stéphane JoosI have a Navlink Component that has a catid prop (a number) <NavLink catid={category.id} to={category.route}> <img src={category.img} alt={category.name}/> <p> {category.name} </p> </NavLink> so it routes to ano...

 
unrelated to your question but why are you putting all your props in the component state?
 
Sorry, i am an absolute beginner, but effectively it's useless
 
can provide an example of the data you are passing? and the code for 'ProductListItem'?
 
Ali , if i replace this.state.cat in the filteredProds function by a number, let's say 11, it works and displays all the products that belongs to the category 11
 
So this probably means the props you are passing are incorrect
 
4:37 PM
This is how the navLink component renders <a catid="11" href="/boissons"><img src="./categories/menuFooter-boissons.jpg" alt="Boissons"><p>Boissons</p></a>
 
Can you show me where and how you are using ProductListFilter?
 
Well i use it in a stateless component (this is were the routes redirects)
export default function CategoryPage(props) {
return (<div>
<h1>Cat page</h1>
<ProductListFilter />
</div>
)
}
 
You need to pass the props in the <ProductListFilter /> component
<ProductListFilter
addToCart={addToCart}
removeFromCart={removeFromCart}
cart={cart}
products={products}
catid={catid}
/>
like this ^
 
4:59 PM
Thanks for your help Ali
 
works? :)
 
Not yet tested, sure it does ;)
 
Alright, good luck buddy
 

last day (15 days later) »