Last active
May 21, 2024 17:40
-
-
Save viswanathsaj/fe9803a65cdb1e17a97e760113b29cdc to your computer and use it in GitHub Desktop.
Implementation for a load more button in React/NextJS using Ghost CMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
Thanks!
Thanks bro
Thanks! This help me a lot
tks dude
Thanks
Was really helpful.
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
Thanks, This was helpful bud.