Created
April 5, 2023 07:05
-
-
Save CodeNinja47/63550e2ac1b2a89a609bafcbdbf046b6 to your computer and use it in GitHub Desktop.
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
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