Layout fetch keeps fetching
Unanswered
Champagne D’Argent posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
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
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
B33fb0n3
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
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
B33fb0n3
@Champagne D’Argent solved?
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
B33fb0n3
@Champagne D’Argent ?
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
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.