Convert WithTracking to function component #142
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 #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 #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.