Skip to content

Instantly share code, notes, and snippets.

@samyarmodabber
Last active March 14, 2024 07:20
Show Gist options
  • Save samyarmodabber/f074841415a9621ff655a676d3fd9eb9 to your computer and use it in GitHub Desktop.
Save samyarmodabber/f074841415a9621ff655a676d3fd9eb9 to your computer and use it in GitHub Desktop.

How-to-Add-Load-More-Button-in-WordPress image refrence: wpxpo

LOAD MORE in Next.js

//Nextjs App: pages/blog/index.js
import Blog from '../../components/post/Blog';
import allPosts from '../../data/posts.json';
import { useState } from 'react';


const Posts = () => {
  allPosts.reverse()
  
  const [visible, setVisible] = useState(20); //20 initial posts

  const showMoreItems = () => {
    setVisible((prevValue) => prevValue + 10); //load 10 more post
  };
  return (
    <div>
      <h1>All Posts</h1>
      
      <Blog posts={allPosts.slice(0, visible)} /> //This component show a list of posts
      
      <button className="" onClick={showMoreItems}>
        Load More
      </button>

    </div>
  );
};

export default Posts;
@samyarmodabber
Copy link
Author

Please leave me a comment if it is useful. Thanks

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