Created
January 22, 2019 13:03
-
-
Save calendee/92cd83c28f7d69e595336d145766cffe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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