export const ProductList = (props) => {
const [search, setSearch] = useState("");
我尝试创建一个常量计数,但不工作
return (
<div id="product-list">
<header>
<input
type="text"
placeholder='Search...'
onChange={(event)=>{
setSearch(event.target.value);
}}
/>
我需要根据过滤器产品动态显示。长度只显示总计
<strong>Product List ({products.length} items)</strong>
</header>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Department</th>
<th>Price</th>
</tr>
</thead>
<tbody>
{products.filter((val)=>{
if(search == "") {
我尝试返回计数 = 0
return val
} else if(val.name.toLocaleLowerCase().includes(search.toLocaleLowerCase())) {
并返回 count = val.length 但 count 不起作用
return val
}
}).map((val, key) =>{
return <tr key={key}>
<td>{val.id}</td>
<td>{val.name}</td>
<td>{val.department}</td>
<td>{val.price}</td>
</tr>;
})}
</tbody>
</table>
</div>
)
}