async function fetchFunction() {
try{
const response = await fetch(`http://url.com`);
const json = await response.json();
}
catch(err) {
throw err;
console.log(err);
}
}
const [products, setProducts] = useState([]);
// Fetch array of products
async function initProducts() {
await fetch('http://127.0.0.1:5000/listProducts')
.then(response => response.json())
.then(response => {
setProducts(response.result);
console.log(response.result);
)
.catch(err => console.error(err));
}
// Get products to html with map function
function getProductsHtml() {
return products.map(product =>
<h1>{product.ProductName}</h1>
<h1>{product.ProductDescription}</h1>
);
}