How to make prerendering work with react server component that uses an api from the same project
Answered
Polar bear posted this in #help-forum
Polar bearOP
Consider this code
http://localhost:3000/api/todo/list is a route in the same project
How can i make this work ?
import { TodoListSchema } from "@/app/lib/schemas/todo"
import { AddForm } from "@/app/add-form"
export default async function Page() {
const request = await fetch("http://localhost:3000/api/todo/list")
const json = await request.json()
const data = TodoListSchema.parse(json)
return (
<div>
<ul>
{
data.map((item) => (<li key={item.id}>{ item.text }</li>))
}
</ul>
<AddForm />
</div>
)
}
http://localhost:3000/api/todo/list is a route in the same project
How can i make this work ?
Answered by Asian black bear
Don't fetch your own route: https://nextjs-faq.com/fetch-api-in-rsc
1 Reply
Asian black bear
Don't fetch your own route: https://nextjs-faq.com/fetch-api-in-rsc
Answer