Hello everyone, is there a way to use both growthb...
# announcements
Hello everyone, is there a way to use both growthbook javascript sdk and growthbook react sdk in the same web app? I'm using the javascript sdk in my middleware in a next.js app and wanted to access the flag in the client side so I was wondering if I could do that or is there an easier way? keep in mind I tried setting the feature flag in the cookies and accessing it but it was undefined on load so I'm looking for another way, thanks again.
Hi Amr, you can use just the React SDK since it uses the JS SDK under the hood ... We expose the same
object, meaning you should be able to accomplish you whatever can in the JS SDK with the React SDK, in addition to the React helpers it provides.
With the one SDK, you can access the flag both server and client side. Let me know if you have any more questions
Wait - I just realized, you cannot use the React SDK in Next 13 because it contains client-side only features, like useEffect. So you're right - you do have to use the JS SDK for your middleware.
@swift-helmet-3648 so if I want the feature flag that was set in the middleware to be accessed in a client side component, what's the best approach? actually initializing another growthbook instance there or is there a cleaner way?
Basically yes. But this is sort of a limitation of Next rather than GrowthBook. You need a way to pass values from the middleware to the client route - outside of cookies, headers, or query params, I don't think there other ways. You can leverage one of these three to pass down the FF value, or use the GB SDK clientside.