Skip to content

Instantly share code, notes, and snippets.

@Fran-A-Dev
Created April 19, 2024 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fran-A-Dev/678ebe8a4e0affb80ab253402dcb88bc to your computer and use it in GitHub Desktop.
Save Fran-A-Dev/678ebe8a4e0affb80ab253402dcb88bc to your computer and use it in GitHub Desktop.
Next.js 14 Core Competencies/3 second latency fetch
async function getCharacters() {
// Simulate 3 seconds of network latency
await new Promise((resolve) => setTimeout(resolve, 3000));
const res = await fetch("http://localhost:4000/characters", {
headers: {
"Content-Type": "application/json", // Indicate that we're expecting JSON
},
next: {
revalidate: 0, // Next.js specific fetch option to opt out of cache
},
});
if (!res.ok) {
throw new Error(`Failed to fetch characters, status: ${res.status}`);
}
return res.json();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment