-
-
Save kapscudi/8b67e4daccb4e8d15cc6faffd3e5981b to your computer and use it in GitHub Desktop.
Implementation for a load more button in React/NextJS using Ghost CMS
This file contains hidden or 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment