Layout fetch keeps fetching
Unanswered
Champagne D’Argent posted this in #help-forum
Champagne D’ArgentOP
I have this layout component:
If something changes in my Layout for example if I open a menu or something it keeps trying to fetch the data and the loading component appears, is there a way to improve this or am I doing something wrong?
Does following:
export default async function RootLayout({ children }: RootLayoutProps) {
const { spaces } = await getSpaces();
If something changes in my Layout for example if I open a menu or something it keeps trying to fetch the data and the loading component appears, is there a way to improve this or am I doing something wrong?
getSpaces
Does following:
export const getSpaces = async () => {
const { session } = await getUserAuth();
const s = await db.select().from(spaces).where(eq(spaces.userId, session?.user.id!));
return { spaces: s };
};
4 Replies
You shouldn’t fetch inside your layout. The layout is only for „layouting“ stuff. So fetch inside your pages. I think your problem is part of this principle 🙂 @Champagne D’Argent
@Champagne D’Argent solved?
@Champagne D’Argent ?
Champagne D’ArgentOP
@B33fb0n3 Never fetch in layout components? I think I fixed it because a component used async, which I removed, going to check it later again.