-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathProductsPage.js
More file actions
31 lines (27 loc) · 1.03 KB
/
ProductsPage.js
File metadata and controls
31 lines (27 loc) · 1.03 KB
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
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 [inStockOnly, setInStockOnly] = useState(false);
const filteredProducts = products.filter(product => {
const matchesSearchTerm = product.name.toLowerCase().includes(searchTerm.toLowerCase());
const matchesInStock = !inStockOnly || product.inStock;
return matchesSearchTerm && matchesInStock;
});
return (
<div>
<h1 className="text-2xl font-bold mb-4">Root Store</h1>
<SearchBar
searchTerm={searchTerm}
setSearchTerm={setSearchTerm}
inStockOnly={inStockOnly}
setInStockOnly={setInStockOnly}
/>
<ProductTable products={filteredProducts} />
</div>
);
}
export default ProductsPage;