Created
October 9, 2018 04:39
-
-
Save gnppro/a8d8f68c037aec5e63cc6e8d5d471557 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Layout from '../components/MyLayout.js' | |
| import Link from 'next/link' | |
| // import fetch from 'isomorphic-unfetch' | |
| import axios from 'axios' | |
| const Index = (props) => ( | |
| <Layout> | |
| <h1>Batman TV Shows</h1> | |
| <ul> | |
| {props.data.map(({show}) => ( | |
| <li key={show.id}> | |
| <Link as={`/p/${show.id}`} href={`/post?id=${show.id}`}> | |
| <a>{show.name}</a> | |
| </Link> | |
| </li> | |
| ))} | |
| </ul> | |
| </Layout> | |
| ) | |
| Index.getInitialProps = | |
| async function() { | |
| // fetch('https://api.tvmaze.com/search/shows?q=batman') | |
| // const data = await res.json() | |
| const res = await axios.get('https://api.tvmaze.com/search/shows?q=batman') | |
| const data = await res.data | |
| console.log(`Show data fetched. Count: ${data.length}`) | |
| return { | |
| data: data | |
| } | |
| } | |
| export default Index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Highlight and format
Original post
^^ Original Comment ^^
^^ Original Comment ^^