En mi página de índice así:
function Index({posts}) { console.log(posts); return ( <div> Homepage {/* {posts && posts.length > 0 && posts.map(post => <h1 key={post._id}>{ post.title}</h1>)} */} </div> ) } Index.getInitialProps = async ctx => { try { const res = await axios({ method: "GET", url: 'https://jsonplaceholder.typicode.com/posts' }) return {posts: res.data} } catch (error) { return {errorLoading: true} } } export default Index; console.log(res.data) funciona correctamente. Pero solo obtengo console.log(posts) sin definir. ¿por qué?
Yo uso la aplicación personalizada. Olvidé agregar pageProps en _app.js. Después de ver https://nextjs.org/docs/advanced-features/custom-app , los arreglo. gracias a todos por ayudarme