I am posting new data to the backend. It is being sent successfully but the section where I fetched these data are not being updated until I press reload on the browser.
Here I am adding the code. Please let me know where am I making the problem? Thanks a lot.
//This is a custom hook where I am fetching data.
const [products, setProducts] = useProductsHook();
const handleAddProduct = () => {
const newProduct = {
name: productName,
image: imageLink,
desc: desc,
price: +price,
quantity: +quantity,
supplier: supplierName,
};
axios.post("http://localhost:5000/api/products", newProduct).then((res) => {
setProducts(products.concat(res.data));
setProductName("");
setImageLink("");
setDesc("");
setPrice("");
setQuantity("");
setSupplierName("");
});
};