Guest User

Untitled

a guest
Jan 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import { NextFunctionComponent, NextContext } from 'next'
  2.  
  3. // Define what an individual item looks like
  4. interface IDataObject {
  5. id: number,
  6. name: string
  7. }
  8.  
  9. // Define the props that getInitialProps will inject into the component
  10. interface IListComponentProps {
  11. items: IDataObject[]
  12. }
  13.  
  14. const List: NextFunctionComponent<IListComponentProps> = ({ items }) => (
  15. <ul>
  16. {items.map((item) => (
  17. <li key={item.id}>
  18. {item.id} -- {item.name}
  19. </li>
  20. ))}
  21. </ul>
  22. )
  23.  
  24. List.getInitialProps = async ({ pathname }: NextContext) => {
  25. const dataArray: IDataObject[] =
  26. [{ id: 101, name: 'larry' }, { id: 102, name: 'sam' }, { id: 103, name: 'jill' }, { id: 104, name: pathname }]
  27.  
  28. return { items: dataArray }
  29. }
  30.  
  31. export default List
Add Comment
Please, Sign In to add comment