Hello! Is there any way to update the trackingCall...
# contributing
r
Hello! Is there any way to update the trackingCallback during the lifetime of a Growthbook instance in the React SDK?
f
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
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
@future-teacher-7046 any thoughts?
f
Here's a modified version of the sandbox. Biggest difference is that I moved
trackingCallback
into it's own
useRef
r
Nice! works perfectly for the second component but it doesn’t seem to be firing the tracking function in the first component 🤔
f
Sorry, had an extra function layer in the
useRef
hook. Should work now
r
ahh, didn’t notice 😊 Thanks a lot!