import React from “react”;
export async function getServerSideProps() {
const res = await fetch(“https://wpsite.com/wp-json/wp/v2/posts”);
const data = await res.json();
return {
props: {
blogs: data,
},
};
}
const Blog = ({ blogs }) => {
return (
<div>
{blogs.length === 0 ? (
<div>Loading</div>
) : (
blogs.map((blog, index) => (
<div key=”{index}”>{blog.title.rendered}</div>
))
)}
</div>
);
};
export default Blog;