Comments (8)
Yeah, same problem here @clintonhalpin, I think Node.js doesn't support natively fetch yet. A work around would be to install and import the package isomorphic-fetch
.
So the example could be changed to something like:
import React from 'react'
import 'isomorphic-fetch'
export default class extends React.Component {
static async getInitialProps () {
const res = await fetch('https://api.company.com/user/123')
const data = await res.json()
return { username: data.profile.username }
}
}
from next.js.
@hnordt Nice, much cleaner!
from next.js.
next.js should absolutely include the isomorphic-fetch
polyfill!
from next.js.
I was missing the isomorphic-fetch
import. Thank you. We actually use that extensively for www.zeit.co
from next.js.
We'll update the blog post
from next.js.
Anyway, great job with Next.js, you and Zeit's team are brillant @rauchg.
from next.js.
+1
Also I'm not sure if I'm doing something wrong. But when I ran the example ( with correction ) Node v.7.0
was complaining that fetch wasn't defined.
My solution was to import axios
and use that instead of fetch
. I'd be happy to open a PR for this in the examples folder!
import React from 'react'
import axios from 'axios'
export default class extends React.Component {
static async getInitialProps () {
const response = await axios('https://api.company.com/user/123')
return { username: response.data }
}
}
from next.js.
The blog was updated, I'm closing this issue.
from next.js.
Related Issues (20)
- Server action throws uncaught exception on network error HOT 3
- TypeScript templates should have read-only props HOT 1
- The focus of the input is lost when typing quickly.
- Issues with Default Language Routing and Router Interceptor in Next.js /app Directory (i18n) HOT 15
- restarting my internet connection (wi-fi) and deleting ``.next`` folder worked for me HOT 1
- I am unable able to deploy one of my blog application due to some issues . I am Unable to resolve it HOT 13
- Production Build Failure after v14.0.2-canary.19 HOT 5
- Server Components under Parallel Nested Routes in `dev` mode infinitely re-render HOT 2
- Docs: No longer any reference to next-env.d.ts in documentation HOT 1
- MongoDb ObjectId import in client component causes unhandled runtime error "Error: Element type is invalid"
- Server stack traces don't match TypeScript source HOT 1
- Unable to delete cookie from route handler HOT 1
- The custom error pages example no longer works HOT 3
- Next Image component within MDX throws error HOT 1
- `pnpm create next-app` build fails HOT 3
- Rendering error while refresh the page (prooduction build) HOT 1
- nextjs 14 - dynamic route js file returns 404 (only in production) HOT 2
- Scroll restoration does not work with app router HOT 1
- Scroll restoration does not work with app router HOT 3
- SSR Issue - Always getting the same page even if the data in database is changed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.