This PR converts the WithTracking class to a function component, using hooks to access the context and dispatch on mount. This allows for better compatibility with libraries that use the legacy context API and old versions of hoist-non-react-statics, which introduced support for static contextType in v3.1.0 (relevant PR). I believe this will fix issue https://github.com/nytimes/react-tracking/issues/137 as well.
This also puts us in a better position to hopefully introduce an API for useTracking that will allow for contextual data to be passed in without wrapping components in the track decorator (issue https://github.com/nytimes/react-tracking/issues/138).
All e2e tests are passing. Unit tests for withTrackingComponentDecorator are mostly broken. I'm not entirely sure the best way to update these tests, as many of them test the internals of the WithTracking class, which are no longer accessible in this implementation.
I would like to do some further digging into whether there are any negative implications to memoizing so many functions with the useCallback hook, which we need to do in order to preserve function identity and avoid undesired rerenders of decorated components.
This PR converts the
WithTracking
class to a function component, using hooks to access the context and dispatch on mount. This allows for better compatibility with libraries that use the legacy context API and old versions ofhoist-non-react-statics
, which introduced support forstatic contextType
in v3.1.0 (relevant PR). I believe this will fix issue https://github.com/nytimes/react-tracking/issues/137 as well.This also puts us in a better position to hopefully introduce an API for
useTracking
that will allow for contextual data to be passed in without wrapping components in thetrack
decorator (issue https://github.com/nytimes/react-tracking/issues/138).All e2e tests are passing. Unit tests for
withTrackingComponentDecorator
are mostly broken. I'm not entirely sure the best way to update these tests, as many of them test the internals of theWithTracking
class, which are no longer accessible in this implementation.I would like to do some further digging into whether there are any negative implications to memoizing so many functions with the
useCallback
hook, which we need to do in order to preserve function identity and avoid undesired rerenders of decorated components.