Fetching inside a child server component
Answered
harshcut posted this in #help-forum
harshcutOP
I have a component
Child inside a page.tsx. Does the Child also update its data after revalidate time specified in page.tsx? Child is also a server component.// page.tsx
export const revalidate = 3600
export default function Page() {
return (
<>
...
<Child />
...
</>
)
}
// child.tsx
const getDataFromDB= cache(async () => {
return await db.select().from(...)
})
export default async function Child() {
const data = await getDataFromDB()
return <main>{data.map(...)}</main>
}3 Replies
yes
Answer
@joulev yes
harshcutOP
thanks. i also tried by making a build and it works. i was wondering if react cache is required here?
@harshcut thanks. i also tried by making a build and it works. i was wondering if react cache is required here?
react.cache is used for deduplication, so if you call the function in two places with the same argument, you should use it. if not, no need