Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created January 25, 2021 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuc-arc-f/e47bcc59fd48f3bc04563fae3ca55dc8 to your computer and use it in GitHub Desktop.
Save kuc-arc-f/e47bcc59fd48f3bc04563fae3ca55dc8 to your computer and use it in GitHub Desktop.
strapi ,Related data sample
// strapi ,Related data sample
import React from 'react'
import Layout from '../components/layout'
import LibCommon from '../libs/LibCommon'
import LibPagenate from '../libs/LibPagenate'
import TopHeadBox from '../components/TopHeadBox'
import IndexRow from './IndexRow';
//
function Page(data) {
var items = data.blogs
// console.log(items)
return (
<Layout>
<div className="body_main_wrap">
<div className="container">test:
<ul>
{items.map((item, index) => {
var categoryName = ""
if(item.category != null){categoryName= item.category.name }
// console.log(item.id, item.category )
console.log(item.id, categoryName ,item.category )
return (<IndexRow key={index}
id={item.id} title={item.title}
date={item.createdAt}
category_name={categoryName} />
)
})}
</ul>
</div>
</div>
</Layout>
)
}
export const getStaticProps = async context => {
const res = await fetch(
`http://localhost:1337/ex-items?_sort=createdAt:DESC&_start=0&_limit=10`,
);
const blogs = await res.json();
// console.log(blogs)
return {
props : {
blogs: blogs,
}
};
}
export default Page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment