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

Introduce useEventListener hook #32027

Merged
merged 3 commits into from
Oct 14, 2024
Merged

Introduce useEventListener hook #32027

merged 3 commits into from
Oct 14, 2024

Conversation

tsapeta
Copy link
Member

@tsapeta tsapeta commented Oct 13, 2024

Why

useEvent is sometimes not enough, especially when the event has no payload or we don't want to use the payload as a component's state but just react to the event.

How

Introduced useEventListener hook, as an alternative version. Also, useEvent will now use it under the hood.

Test Plan

  • Checked if existing useEvent usages in NCL (only expo-video right now) work as expected
  • Replaced one traditional useEffect that adds and removes the listener with the new useEventListener

@expo-bot expo-bot added the bot: passed checks ExpoBot has nothing to complain about label Oct 13, 2024
@tsapeta tsapeta force-pushed the @tsapeta/use-event-listener branch from 5adb8f2 to 1666ee6 Compare October 13, 2024 21:13

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@tsapeta tsapeta force-pushed the @tsapeta/use-event-listener branch from 1666ee6 to 4f500f6 Compare October 13, 2024 21:15
@tsapeta tsapeta marked this pull request as ready for review October 13, 2024 21:21
Copy link
Contributor

Subscribed to pull request

File Patterns Mentions
docs/** @Simek, @amandeepmittal
packages/expo/** @ide, @tsapeta, @brentvatne

Generated by CodeMention

@tsapeta tsapeta requested review from aleqsio and lukmccall October 13, 2024 21:22
@expo-bot
Copy link
Collaborator

📘 Your docs preview website is ready!

@@ -15,7 +15,7 @@
- Add initial version of DOM Components and `expo/dom` module. ([#30938](https://github.com/expo/expo/pull/30938) by [@EvanBacon](https://github.com/EvanBacon))
- Support `URL.canParse`. ([#30697](https://github.com/expo/expo/pull/30697) by [@EvanBacon](https://github.com/EvanBacon))
- Add minimal `TextDecoder` support to native client platforms. ([#29620](https://github.com/expo/expo/pull/29620) by [@EvanBacon](https://github.com/EvanBacon))
- Introduced `useEvent` hook for EventEmitter objects (e.g. native modules and shared objects). ([#29056](https://github.com/expo/expo/pull/29056) by [@tsapeta](https://github.com/tsapeta))
- Introduced `useEvent` and `useEventListener` hooks for EventEmitter objects (e.g. native modules and shared objects). ([#29056](https://github.com/expo/expo/pull/29056), [#32027](https://github.com/expo/expo/pull/32027) by [@tsapeta](https://github.com/tsapeta))
Copy link
Contributor

Choose a reason for hiding this comment

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

🤨 Why not a new changelog entry?

Copy link
Member Author

@tsapeta tsapeta Oct 14, 2024

Choose a reason for hiding this comment

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

I just thought that since the useEvent hasn't been published yet, I can merge them as they are related. It seems better for someone who reads the changelog.

@tsapeta tsapeta merged commit 120c61f into main Oct 14, 2024
2 checks passed
@tsapeta tsapeta deleted the @tsapeta/use-event-listener branch October 14, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: passed checks ExpoBot has nothing to complain about preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants