1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/test/integration/lambdas/pages/fetch.js

30 lines
668 B
JavaScript
Raw Normal View History

import fetch from 'isomorphic-unfetch'
import React from 'react'
export default class extends React.Component {
static async getInitialProps () {
try {
const res = await fetch('')
const text = await res.text()
console.log(text)
return {text}
} catch (err) {
if (err.message.includes('is not a function')) {
return {failed: true, error: err.toString()}
}
return {error: err.toString()}
}
}
render () {
const {failed, error, text} = this.props
return <div className='fetch-page'>
{failed ? 'failed' : ''}
{error}
<div id='text'>
{text}
</div>
</div>
}
}