我是 React Js 的新手,所以我自己找不到解决问题的方法,请帮助我。
我正在一个带有博客页面的网站上工作,博客应该在页面上动态显示。当页面加载时,我希望它有 4 个博客,下面会有一个按钮,所以当用户点击它时,React 应该渲染并显示其余的博客。
到目前为止,我的代码如下所示:
import { blogs} from "./blogs";
import { Blog} from "./Blog";
function BlogList() {
const cardComponent = blogs.slice(0,6).map((blog, i) => {
return (
<Blog
key={i}
id={blogs[i].id}
img={blogs[i].img.src}
date={blogs[i].date}
title={blogs[i].title}
img2={blogs[i].img2.src}
logoTitle={blogs[i].logoTitle}
text={blogs[i].text}
/>
);
});
return (
<div>{cardComponent}</div>
)
}`````
**This code lets me display 6 blogs when the page is loaded, what I want to do is add "Load More" button under these already loaded 6 blogs, when the user clicks the button it should render and display another 4 blogs from "blogs", and again have Load More button.** Any help will be greatly appreciated,
Thank you.