DEV Community

Discussion on: Getting Started with Next.js: Part 3 - API Routes

Collapse
 
dipakahirav profile image
Dipak Ahirav

No, you don't need to add an import statement for the fetch API when using it in Next.js for client-side data fetching, as it is a browser-based API available globally in the browser environment. Your current code for the HomePage component is correct as it stands for use within a Next.js application that renders on the client-side. If your code runs on the server (for example, in getServerSideProps or other server-side functions), and you need to make HTTP requests, you might consider using Node.js compatible libraries like axios or node-fetch, which would require an import. But for client-side usage like in your component, no import statement for fetch is necessary.