How to properly pass data from layout.tsx?
Answered
Silver carp posted this in #help-forum
Silver carpOP
How can I fetch the data from a request once and use it throughout the dashboard? I'm having issues passing data from the
layout.tsx
to props.children
but I just realized either way, each page I go to will refetch the data so I'm curious on what I can do?Answered by James4u
https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#example
@Silver carp check out this one
@Silver carp check out this one
5 Replies
Silver carpOP
I know If I'm using the
fetch
in next I can automatically make it so that it caches but I'm using supabaseSo.. in that case would I need to make my own external express server that handles stuff like that?
https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#example
@Silver carp check out this one
@Silver carp check out this one
Answer
import { cache } from 'react'
export const getItem = cache(async (id: string) => {
const item = await db.item.findUnique({ id })
return item
})
Silver carpOP
Amazing! Thanks