Hi team :wave:, I'm currently looking at integrat...
# ask-questions
q
Hi team 👋, I'm currently looking at integrating GB into a NextJS app router project for the first time so this is possibly an easy question, hoping someone could help clear some things up. My aim is to forward assigned variations from server components to the client in order to push these to the datalayer (following docs.growthbook.io/lib/react#…), but I opted for using the
GrowthBookClient
to prevent having to recreate a GrowthBook instance on every request (as far as I understand). This instance does not seem to have the
getDeferredTrackingCalls
method on it however. Is there a way to access the assigned variations from
GrowthBookClient
instead, or should I look to use
GrowthBook
instances? If the latter, what is the recommended way of sharing this instance between nested server components to minimize prop drilling?
f
Hi @quick-midnight-66579 good morning! Yep, that's expected.
getDeferredTrackingCalls()
is available on the JS SDK
GrowthBook
instance, not
GrowthBookClient
. For Next.js App Router / Server Components, I'd follow the SSR docs you linked and create a
GrowthBook
instance server-side for the request, evaluate the flags, then call:
getDeferredTrackingCalls()
and pass that small tracking payload to a client component that pushes to the dataLayer.
I'd avoid sharing one global GrowthBook instance across requests, since attributes/tracking are user-specific. To avoid prop drilling, the usual pattern is to centralize GrowthBook setup in the page/layout or a request-scoped helper, then pass down only the evaluated flag values/payload where needed, plus one tracking component near the top of the tree.
q
Many thanks, that clears it up 😃
f
My absolute pleasure to assist 🌻