#How do I enable top level await in next.js v13.5.4?
1 messages · Page 1 of 1 (latest)
Hi @ivory talon. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, you can use top-level await in Next.js version 13.5.4. This feature is particularly useful when you are fetching data in your application. Here's an example of how you can use it:
export default async function Page() {
const res = await fetch('<https://api.example.com/...'>);
// The return value is *not* serialized
// You can use Date, Map, Set, etc.
const data = res.json();
return '...';
}
This code is part of the new App Router feature in Next.js 13.4, which allows you to fetch data using the familiar async and await syntax. By default, all components are React Server Components, so data fetching happens securely on the server.