-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathProductsPage.js
More file actions
33 lines (29 loc) · 885 Bytes
/
ProductsPage.js
File metadata and controls
33 lines (29 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// src/components/ProductsPage.js
import { useState } from 'react';
import jsonData from './../../data.json';
import SearchBar from './SearchBar';
import ProductTable from './ProductTable';
function ProductsPage() {
const [products, setProducts] = useState(jsonData);
const [searchTerm, setSearchTerm] = useState("");
const [showInStock, setShowInStock] = useState(false);
const filteredProducts = products
.filter(product =>
product.name.toLowerCase().includes(searchTerm.toLowerCase())
)
.filter(product =>
!showInStock || product.inStock
);
return (
<div>
<h1>Root Store</h1>
<SearchBar
onSearch={setSearchTerm}
showInStock={showInStock}
onToggleInStock={() => setShowInStock(!showInStock)}
/>
<ProductTable products={filteredProducts} />
</div>
);
}
export default ProductsPage;