daily pastebin goal
72%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react'
  2. import { NextContext } from 'next'
  3.  
  4. // Define what an individual item looks like
  5. interface IDataObject {
  6.   id: number,
  7.   name: string
  8. }
  9.  
  10. // Define the props that getInitialProps will inject into the component
  11. interface IListClassProps {
  12.   items: IDataObject[]
  13. }
  14.  
  15. class List extends React.Component<IListClassProps> {
  16.   static async getInitialProps({ pathname }: NextContext) {
  17.     const dataArray: IDataObject[] =
  18.       [{ id: 101, name: 'larry' }, { id: 102, name: 'sam' }, { id: 103, name: 'jill' }, { id: 104, name: pathname }]
  19.  
  20.     return { items: dataArray }
  21.   }
  22.  
  23.   render() {
  24.     return (
  25.       <ul>
  26.         {this.props.items.map((item) => (
  27.           <li key={item.id}>
  28.             {item.id} -- {item.name}
  29.           </li>
  30.         ))}
  31.       </ul>
  32.     )
  33.   }
  34. }
  35.  
  36. 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