Skip to content

Instantly share code, notes, and snippets.

@CodeNinja47
Created April 5, 2023 07:05
Show Gist options
  • Save CodeNinja47/63550e2ac1b2a89a609bafcbdbf046b6 to your computer and use it in GitHub Desktop.
Save CodeNinja47/63550e2ac1b2a89a609bafcbdbf046b6 to your computer and use it in GitHub Desktop.
import Link from "next/link"
const getTodos = async () => {
try {
const res = await fetch('http://localhost:3000/api/todo');
const data = (await res).json();
return data;
} catch (error) {
return [];
}
}
export default async function Todo() {
let data: any = await getTodos();
return <div className="todo-container">
<div className="todo-list">
{data.map((item: any, index: number) => <div
key={index}
className="todo-item">
<Link href={`/todo/${item.id}`} className="todo-title">{item.title}:</Link>
<div className="todo-description">{item.description}</div>
</div>)}
</div>
</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment