Skip to content

Question: How can I access the the current value of variables outside of dispatch after e.g. state changes #225

@natterstefan

Description

@natterstefan

Hello everyone,

I am dealing with the following problem:

  • 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.

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions