Skip to content

Instantly share code, notes, and snippets.

@calendee
Created January 22, 2019 13:03
Show Gist options
  • Save calendee/92cd83c28f7d69e595336d145766cffe to your computer and use it in GitHub Desktop.
Save calendee/92cd83c28f7d69e595336d145766cffe to your computer and use it in GitHub Desktop.
import { NextFunctionComponent, NextContext } from 'next'
// Define what an individual item looks like
interface IDataObject {
id: number,
name: string
}
// Define the props that getInitialProps will inject into the component
interface IListComponentProps {
items: IDataObject[]
}
const List: NextFunctionComponent<IListComponentProps> = ({ items }) => (
<ul>
{items.map((item) => (
<li key={item.id}>
{item.id} -- {item.name}
</li>
))}
</ul>
)
List.getInitialProps = async ({ pathname }: NextContext) => {
const dataArray: IDataObject[] =
[{ id: 101, name: 'larry' }, { id: 102, name: 'sam' }, { id: 103, name: 'jill' }, { id: 104, name: pathname }]
return { items: dataArray }
}
export default List
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment