Answer the question
In order to leave comments, you need to log in
How to fetch data using fetch?
There is such an endpoint on the back
app.get('/api/category', async(req, res) => {
try {
let categories = await Category.find({});
res.send(categories)
} catch(e) {
res.send(e)
}
});
async function getCategories() {
let categories;
await fetch(`${api}/category`)
.then((res) => {
return res.json();
}).then((response) => {
categories = response;
})
.catch((e) => {
console.log(e);
})
return categories;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question