orange-rocket-9599
01/24/2023, 10:52 PMuseGrowthbook().ready
is being set back to false. The configuration looks simple enough, so I'm not sure where I'm going wrong here. Any advice would be appreciatedconst gb = new GrowthBook({
apiHost: "<https://cdn.growthbook.io>",
clientKey: "<our_key>",
enableDevMode: query["debug_experiments"] === "true",
trackingCallback: (experiment, result) => {
// TODO: Use your real analytics tracking system
console.log("Viewed Experiment", {
experimentId: experiment.key,
value: result.value,
});
},
});
and then
useEffect(() => {
// Load features from the GrowthBook API
gb.loadFeatures()
.then(() => {
// Redacted loggedOutId logic
console.log("Setting GB attributes");
gb.setAttributes({
id: loggedOutId,
path: asPath.split("?")[0],
});
})
.catch(err => {
console.log("ERROR LOADING FEATURES", err);
});
}, []);
fresh-football-47124
orange-rocket-9599
01/24/2023, 10:54 PMfresh-football-47124
orange-rocket-9599
01/24/2023, 11:01 PM_app.tsx
there looks like what we want. But the only difference that I see compared to what I tried is the use of decryptionKey
, so I'm not sure why that configuration isn't working for usfuture-teacher-7046
ready
flag back to false. My guess is that it's creating a 2nd instance of GrowthBook and that one isn't calling loadFeatures
orange-rocket-9599
01/24/2023, 11:20 PM_app.tsx
is getting re-rendered immediately but that's overwriting the gb
instance that had its attributes & features set inside a useEffect
. I should be able to figure that out on my end - thanks for the advice!future-teacher-7046
orange-rocket-9599
01/24/2023, 11:26 PM_App
is actually intended to render twice in many cases.
I must've been going through the setup without paying full attention, as actually following the steps correctly and initializing the GrowthBook instance outside of the App
component works perfectly fine. The problem only happens when running _const_ gb = _new_ GrowthBook({
inside of App
. Sorry about that and thanks for getting me an answer so quickly!