Next.js Discord

Discord Forum

How to properly pass data from layout.tsx?

Answered
Silver carp posted this in #help-forum
Open in Discord
Avatar
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?

5 Replies

Avatar
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 supabase
So.. in that case would I need to make my own external express server that handles stuff like that?
Answer
Avatar
import { cache } from 'react'
 
export const getItem = cache(async (id: string) => {
  const item = await db.item.findUnique({ id })
  return item
})
Avatar
Silver carpOP
Amazing! Thanks