I don't know why but I get this error constantly when I change the option in the selector ."react-dom.development.js:4091 Uncaught TypeError: onItemSelect is not a function" :(
import React from "react";
import Product from "./Product";
import ListGroup from "./listGroup";
export default function Main(props) {
const { products, onAdd, categories } = props;
const handleCategorySelect = () => {
console.log("Click");
};
return (
<main className="block col-2">
<ListGroup items={categories} />
<h2>Products</h2>
<div>
{products.map((product) => (
<Product
key={product.id}
product={product}
onAdd={onAdd}
onItemSelect={handleCategorySelect}
></Product>
))}
</div>
</main>
);
}
and my listGroup.jsx is :
import React from "react";
function ListGroup(props) {
const { items, onItemSelect } = props;
return (
<form>
<select
value=""
id="category"
name="category"
onChange={() => onItemSelect()}
>
<option hidden value="">
Choose here
</option>
{items.map((item) => (
<option key={item._id}>{item.name}</option>
))}
</select>
</form>
);
}
export default ListGroup;
and also how can I pass the item object to onChange ? I mean if it was a list group I would go with :
<ul className="list-group">
{items.map(item => (
<li
onClick={() => onItemSelect(item)}
key={item[valueProperty]}
className={
item === selectedItem ? "list-group-item active" : "list-group-item"
}
>
{item[textProperty]}
</li>
))}
</ul>
but with select and option I don't know How to do it.