You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a component that sets up the app-wide context (useTracking({ context })
context is updated async after the component mounts and sometimes even when the route changes
additional info is relevant to dispatch but should not be part of the event (not added to context), let's say it is called dispatchInfo
the logic inside dispatch should be able to access the current value of context and dispatchInfo at any time, but it doesn't. It's stuck to the first value it gets.
Thanks for submitting an issue @natterstefan -- I think this is because the current useTracking() hook does not accept a dependency array (so it never sees the updated state). I guess technically it could, but that has other implications and might be a bigger change than it's worth.
As a workaround, using a useRef for the dispatchInfo, seems to do the trick? I updated your codesandbox example here.
Hello everyone,
I am dealing with the following problem:
useTracking({ context })
context
is updated async after the component mounts and sometimes even when the route changesdispatch
but should not be part of theevent
(not added tocontext
), let's say it is calleddispatchInfo
dispatch
should be able to access the current value ofcontext
anddispatchInfo
at any time, but it doesn't. It's stuck to the first value it gets.Here is an example: https://codesandbox.io/s/react-tracking-example-mdqh9h?file=/src/App.js. Could you please look at line 28+ to see what I mean, and open the console to see the logs?
The text was updated successfully, but these errors were encountered: