Created
January 25, 2021 06:56
-
-
Save kuc-arc-f/e47bcc59fd48f3bc04563fae3ca55dc8 to your computer and use it in GitHub Desktop.
strapi ,Related data sample
This file contains 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
// 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