Skip to content

Commit 8a219c7

Browse files
author
WebDeveloperGuide
committed
Fix: Product do not load when on first page and search something or filter by price
1 parent 18c1c9a commit 8a219c7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

web_panel/src/components/Products.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const Products = () => {
1212
const [priceFilter,setPriceFilter] = useState(10000);
1313
const [searchTerm, setSearchTerm] = useState('');
1414
const [sortByFilter, setSortByFilter] = useState('');
15+
const [filter, setFilter] = useState('');
1516
const allProducts = useSelector((state)=> state.allProducts);
1617
const { products, numOfPages, sortBy, searchText, price } = allProducts;
1718
const productsPerPage = 9;
@@ -42,14 +43,15 @@ const Products = () => {
4243
if(currentPage <= numOfPages){
4344
dispatch(getProducts(currentPage,productsPerPage, sortBy, searchTerm, price));
4445
}
45-
},[currentPage])
46+
},[currentPage,filter])
4647

4748

4849
//Call Function after stop typing text
4950
useEffect(() => {
5051
dispatch(resetProducts());
5152
const delaySearchFunc = setTimeout(() => {
52-
setCurrentPage(0);
53+
setCurrentPage(0);
54+
setFilter(searchTerm+priceFilter)
5355
}, 1500)
5456

5557
window.addEventListener("scroll", loadMoreProduct);

0 commit comments

Comments
 (0)