Next.js Discord

Discord Forum

Data fetching from param values

Answered
MarkMiklos posted this in #help-forum
Open in Discord
So i have a special use case where I need to fetch data based on a subtype dynamic param, but i need to access this value in other components as well, where params not available, and also this fetch returns a tenantId that i need to use in a lot of component.

My question is that what is my best option here?
Currently i am doing a check for domains, etc and set a a cookie with that subtype, and whenever i need to fetch data with the subtype param I just fetch it from the cookie value, not from the params, and also I set the tenantId, and use that as well from the cookies.

Is it okay to do so, or I am completely wrong on this? If so, what would be the way to go?
Answered by Anay-208 | Ping in replies
If I understood correctly, you’re setting your param name to the Cookie.

A better option would be to pass it to a client component and create a context with the param, or just pass the param to the required component
View full answer

9 Replies

Answer
If there is 5 components, I recommend useContext
Or you can get in the client component using new URL(), it has some properties with the help of what you can get pathname
@MarkMiklos resolved?
@Anay-208 | Ping in replies <@691640174077280263> resolved?
yeah just one small question, pass down the params, and fetch again in the component (as most of my components are server components) or pass down the fetched data?
You can just pass it down, if its server components, and just use props. to get it
you mean just get the passed down data from the props right? no need to fetch it again?
you can pass it down to props