SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- 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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.