Created
April 19, 2024 15:40
-
-
Save Fran-A-Dev/678ebe8a4e0affb80ab253402dcb88bc to your computer and use it in GitHub Desktop.
Next.js 14 Core Competencies/3 second latency fetch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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