Sign in
Sign up

    Live Loading

    Global Posts

    View on GitHub
TypeScript と Amplify とISR

@arakida - 3y

pages/index.tsx

1type Props = {
2 items: Item[]
3}
4
5export const getStaticProps: GetStaticProps<Props> = async () => {
6 const API: GraphQLAPIClass = withSSRContext().API
7
8 const queryVariables: ListItemQueryVariables = {
9 sortDirection: ModelSortDirection.DESC,
10 limit: 20,
11 }
12
13 const res = (await API.graphql({
14 query: listItem,
15 variables: queryVariables,
16 })) as GraphQLResult<ListItemQuery>
17
18 const items = res.data?.listItem?.items ?? []
19
20 return {
21 props: {
22 items: items,
23 },
24 revalidate: 5,
25 }
26}
27
28const Home: NextPage<Props> = ({ items }) => {
29 return (
30 <>
31 {items.map((v, i) => (
32 <div key={i}>
33 <h1>{v.title}</h1>
34 <h2>{v.owner}</h2>
35 <p>{v.content}</p>
36 </div>
37 ))}
38 </>
39 )
40}
41
42export default Home
Comment