daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
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. OK, I Understand
 
Top