https://www.growthbook.io/ logo
#contributing
Title
# contributing
r

rhythmic-psychiatrist-74694

09/04/2022, 5:01 AM
Hello! Is there any way to update the trackingCallback during the lifetime of a Growthbook instance in the React SDK?
f

fresh-football-47124

09/04/2022, 6:42 AM
Hi Eirik, you’re welcome to call another function from within that method that you can adjust what it does as needed
just be careful not to bias your results
r

rhythmic-psychiatrist-74694

09/05/2022, 12:51 PM
Hey Graham! Thanks for the reply. I don’t think I quite understand what you mean. Here is a somewhat simplified sandbox of what my issue is: https://codesandbox.io/s/lucid-vaughan-p4402x?file=/src/App.js I want to change the trackingCallback based on some data that is not available immediately, but I do not want to delay initialising the growthbook instance so that I can render features as fast as possible. I have a working solution where I reinitialize growthbook with the attributes/features from the old instance but then I lose which experiments are already tracked becuase
_trackedExperiments
is private and doesn’t have a setter and I might end up tracking the same experiment twice in a session. This could be solved by deduplicating later, but it would be nice to avoid. Do you know how I could accomplish this?
f

fresh-football-47124

09/05/2022, 1:11 PM
@future-teacher-7046 any thoughts?
f

future-teacher-7046

09/05/2022, 1:49 PM
Here's a modified version of the sandbox. Biggest difference is that I moved
trackingCallback
into it's own
useRef
r

rhythmic-psychiatrist-74694

09/05/2022, 1:59 PM
Nice! works perfectly for the second component but it doesn’t seem to be firing the tracking function in the first component 🤔
f

future-teacher-7046

09/05/2022, 2:06 PM
Sorry, had an extra function layer in the
useRef
hook. Should work now
r

rhythmic-psychiatrist-74694

09/05/2022, 2:08 PM
ahh, didn’t notice 😊 Thanks a lot!
7 Views