Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert WithTracking to function component #142

Merged
merged 11 commits into from
Oct 18, 2019

Conversation

bgergen
Copy link
Collaborator

@bgergen bgergen commented Oct 14, 2019

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

Copy link
Collaborator

@tizmagik tizmagik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! 💪

@tizmagik tizmagik merged commit b37874a into nytimes:master Oct 18, 2019
@bgergen bgergen deleted the decorator-use-hooks branch October 19, 2019 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants