Skip to content

Instantly share code, notes, and snippets.

@willie-hung
Last active July 12, 2023 17:39
Show Gist options
  • Save willie-hung/207b31818b558377065a7dbbcbb749b1 to your computer and use it in GitHub Desktop.
Save willie-hung/207b31818b558377065a7dbbcbb749b1 to your computer and use it in GitHub Desktop.
post_5
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