Hi,
I’m recently working on local development with ghost + nextjs. and I’m totally new on the API things so I’m trying my best to understand it.
Goal:
Want to create a pagination for my archive page
Problem:
Can’t get meta
object from posts.browse()
/* ghost.js */
export async function getPosts(limit, page) {
return await api.posts.browse({ limit: limit ? limit : 'all', page: page ? page : 1 }).catch((err) => {
console.error(err)
})
}
Result:
undefined
return in console.log
/* latest.js */
export async function getStaticProps() {
// How many posts should appear on the page
const postsPerPage = 6
// Declaring a new variable (posts/pages) and set the data into the variable.
const posts = await getPosts(postsPerPage)
if (!posts) {
return {
notFound: true,
}
}
return {
props: { posts }
}
}
/* latest.js */
export default function Latest({ posts }) {
useEffect(() => {
console.log(posts.meta)
});
return (
<Main>...
Reading from official docs doesn’t not solve my problem.
Postman:
But in Postman
I can see there’s a meta
property.