Home.getInitialProps = async ctx => {
/* try {
const res = await axios.get('http://localhost:1337/api/' + 'pages');
const Pages = res.data;
// console.log(Pages);
return { Pages};
// return { HomeAccordition };
} catch (error) {
return { error };
}
*/
let Pages =
"'http://localhost:1337/api/' + 'pages'";
let homeAaccorditions =
"'http://localhost:1337/api/' + 'home-accorditions'";
let Menus =
"'http://localhost:1337/api/' + 'menus'";
let HeroSections =
"'http://localhost:1337/api/' + 'hero-sections'";
const requestPages = axios.get(Pages);
const requesthomeAaccorditions = axios.get(homeAaccorditions);
const requestMenus = axios.get(Menus);
const requestHeroSections = axios.get(HeroSections);
axios
.all([requestPages, requesthomeAaccorditions, requestMenus, requestHeroSections])
.then(
axios.spread((...responses) => {
const requestPages = responses[0];
const requesthomeAaccorditions = responses[1];
const requestMenus = responses[2];
const requestHeroSections = responses[3];
// use/access the results
console.log(requestPages, requesthomeAaccorditions, requestMenus, requestHeroSections );
})
)
.catch(errors => {
// react on errors.
console.error(errors);
});
};
export default Home;
//Home.getInitialProps = getInitialProps;
looking for a easy solutions to this. i was intended to return these responses so that we can call them in a component
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (3)
You have commented out the only
return
statement, so the function retunsundefined
.there are return statement you may see it
even this code will not run and it will also return undefined.
i checked and posted here
that return statement is not in the body of the main function.
The try/catch statement won't catch an error that occurs in a callback.
the "callback" in the
.then
isn't a function, it's a statement, unlessaxios.spread
returns a function?