Skip to content

Instantly share code, notes, and snippets.

@viswanathsaj
Last active December 17, 2023 04:45
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save viswanathsaj/fe9803a65cdb1e17a97e760113b29cdc to your computer and use it in GitHub Desktop.
Save viswanathsaj/fe9803a65cdb1e17a97e760113b29cdc to your computer and use it in GitHub Desktop.
Implementation for a load more button in React/NextJS using Ghost CMS
// Make sure you are pulling ALL your posts from the ghost API [No limit]
function LatestPost (props) {
const [ postNum, setPostNum] = useState(3); // Default number of posts dislplayed
function handleClick() {
setPostNum(prevPostNum => prevPostNum + 3) // 3 is the number of posts you want to load per click
}
return (
<div>
{props.posts.slice(0, postNum).map(post => (
<div key={post.id}>
//...Post Data
</div>
))}
<button onClick={handleClick}>Load More</button>
</div>
)
}
export default LatestPost
@thisisgurkaran
Copy link

Thanks, This was helpful bud.

@kubanych4
Copy link

Thanks!

@thewebalchemist
Copy link

Thanks bro

@byjuanberrios
Copy link

Thanks! This help me a lot

@vdavidmarques
Copy link

tks dude

@kulterryan
Copy link

Thanks

@Amejro
Copy link

Amejro commented Feb 28, 2023

Was really helpful.

@thefubon
Copy link

Can you please tell me how to hide the button when all objects have been loaded?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment