Although there is a change in State and useEffect is used to refresh the page when there is a change ... The state changes normally but there is some delay in redefining the state so the page is not interpreted correctly. Attach the code I would love for answers... Thanks in advance.
let { category } = useParams();
const [products, setProducts] = useState([]);
const [filterProducts, setFilterProducts] = useState([]);
useEffect(async () => {
try {
let res = await utils.GetAllItems("http://localhost:5000/product");
setProducts(res.data.Products);
}
catch (error) {
alert(error.response.data.message);
}
},[])
*useEffect(()=>
{
if(category != "all") {
let p = products.filter(x => x.Category == category);
console.log(p);
setFilterProducts(p);
console.log(filterProducts);
}
else {
setFilterProducts(products);
}*
},[category])