Last active
July 12, 2023 17:39
-
-
Save willie-hung/207b31818b558377065a7dbbcbb749b1 to your computer and use it in GitHub Desktop.
post_5
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
interface Todo { | |
userId: number; | |
id: number; | |
title: string; | |
completed: boolean; | |
} | |
async function getData() { | |
const res = await fetch("https://jsonplaceholder.typicode.com/todos"); | |
if (!res.ok) { | |
throw new Error("Failed to fetch data"); | |
} | |
return res.json(); | |
} | |
export default async function Page() { | |
const todos = await getData(); | |
return ( | |
<> | |
<h1>All the Todos 📝</h1> | |
{todos.map((todo: Todo) => ( | |
<div key={todo.id}> | |
<p> | |
{todo.id} : {todo.title} | |
</p> | |
</div> | |
))} | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment