Created
January 22, 2019 13:05
-
-
Save calendee/3caca788f339763a5c98bd092449e3a0 to your computer and use it in GitHub Desktop.
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
import React from 'react' | |
import { 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 IListClassProps { | |
items: IDataObject[] | |
} | |
class List extends React.Component<IListClassProps> { | |
static async getInitialProps({ pathname }: NextContext) { | |
const dataArray: IDataObject[] = | |
[{ id: 101, name: 'larry' }, { id: 102, name: 'sam' }, { id: 103, name: 'jill' }, { id: 104, name: pathname }] | |
return { items: dataArray } | |
} | |
render() { | |
return ( | |
<ul> | |
{this.props.items.map((item) => ( | |
<li key={item.id}> | |
{item.id} -- {item.name} | |
</li> | |
))} | |
</ul> | |
) | |
} | |
} | |
export default List |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment