I have a route that fetches JSON data from an API and res.send it to my webpage component.
app.get('/search-data', (req, res) => {
fetch(url)
.then(res => res.json())
.then(data => {
res.send({ data });
})
.catch(err => {
res.redirect('/error')
})
I want to make multiple fetch requests. I think I need to use Promise.all but how do I format it?
My component receives one data array:
async componentDidMount() {
const response = await fetch('/search-data');
const res = await response.json();
...