Skip to content

Fix misuse of new event emitter API in useOrientation hook #1661

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

Merged
merged 3 commits into from
Nov 14, 2021

Conversation

ethanshar
Copy link
Collaborator

@ethanshar ethanshar commented Nov 11, 2021

Description

Fix misuse of new event emitter API in useOrientation hook

Changelog

Fix event emitter warning coming from useOrientation hook

@ethanshar ethanshar requested a review from M-i-k-e-l November 11, 2021 14:55
@ethanshar ethanshar added the Important for Next Release PR that must be included in the release version label Nov 14, 2021

const orientationChangeListener = useCallback(() => {
setOrientation(Constants.orientation);
}, []);

useEffect(() => {
Constants.addDimensionsEventListener(orientationChangeListener);
return () => Constants.removeDimensionsEventListener(orientationChangeListener);
listener.current = Constants.addDimensionsEventListener(orientationChangeListener);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need the useRef here:

const listener = Constants.addDimensionsEventListener(orientationChangeListener);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point 👌
Fixed

@M-i-k-e-l M-i-k-e-l merged commit ee504da into master Nov 14, 2021
ethanshar added a commit that referenced this pull request Nov 15, 2021
* Fix misue of new event emitter API in useOrientation hook

* keep listener inside clouser instead of using ref

* Fix lint error
@ethanshar ethanshar deleted the fix/lastEventEmitterWarning branch April 18, 2022 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Important for Next Release PR that must be included in the release version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants