Extra: Ensure better maintainability by eliminating redundant imports;
27 lines
698 B
TypeScript
27 lines
698 B
TypeScript
import {apolloClient} from 'graphql/apolloClient';
|
|
import {GET_PRODUCTS} from 'graphql/queries/getProducts';
|
|
import {GetStaticProps} from 'next';
|
|
|
|
export const getStaticProps: GetStaticProps = async () => {
|
|
const {data} = await apolloClient.query({
|
|
query: GET_PRODUCTS,
|
|
variables: {first: 10},
|
|
});
|
|
|
|
return {
|
|
props: {
|
|
products: data.products.edges.map((e: any) => e.node),
|
|
},
|
|
revalidate: 300,
|
|
};
|
|
}
|
|
|
|
export default function Home({products}: { products: any[] }) {
|
|
return (
|
|
<div>
|
|
{products.map(p => (
|
|
<div key={p.uuid}>{p.name} — £{p.minPrice}</div>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|