Skip to content

Instantly share code, notes, and snippets.

@calendee
Created January 22, 2019 13:05
Show Gist options
  • Save calendee/3caca788f339763a5c98bd092449e3a0 to your computer and use it in GitHub Desktop.
Save calendee/3caca788f339763a5c98bd092449e3a0 to your computer and use it in GitHub Desktop.
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