better approach for contexts in nextjs
Unanswered
American Chinchilla posted this in #help-forum
American ChinchillaOP
So in order to use Context from react i have to mark component as "use client" which is not really optimal
but i dont really see other way than using Context in my app
scenario:
imagine a dashboard to manage guilds
you have a /dashboard to select which guild you want to manage
and then /dashboard/id to manage selected guild
to not fetch guilds each time they are needed i decided to make Context providers for all guilds and for selected guild is that good approach?
but i dont really see other way than using Context in my app
scenario:
imagine a dashboard to manage guilds
you have a /dashboard to select which guild you want to manage
and then /dashboard/id to manage selected guild
to not fetch guilds each time they are needed i decided to make Context providers for all guilds and for selected guild is that good approach?
4 Replies
@American Chinchilla So in order to use Context from react i have to mark component as "use client" which is not really optimal
but i dont really see other way than using Context in my app
scenario:
imagine a dashboard to manage guilds
you have a /dashboard to select which guild you want to manage
and then /dashboard/id to manage selected guild
to not fetch guilds each time they are needed i decided to make Context providers for all guilds and for selected guild is that good approach?
to not fetch guilds each time they are neededyou can use
unstable_cache to store the data for many requests OR use plain cache if you want to do the same query for the laout and page and only want it cached for each requestAmerican ChinchillaOP
how does the unstable_cache work
Gull Terrier
i like this. just make sure to invalidate this cache if a new guild is entered/deleted/edited