-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Summary
When writing a Turbo Module that contains an EventEmitter, you need to change your struct annotation from REACT_MODULE to REACT_TURBO_MODULE in order for the JS EventEmitter to be returned from the module.
It might be nice to include an example somewhere that shows a module that uses REACT_TURBO_MODULE and subscribes to the EventEmitter so users know when to use that over REACT_MODULE.
Motivation
I was running into an issue where I was trying to subscribe to an event in a turbo module:
useEffect(() => {
const subscription = NativeIRMenuItemManager.onMenuItemPressed(handleMenuItemPressed)
return () => {
subscription.remove()
}
}, [handleMenuItemPressed])
But the function kept throwing an error saying that the function was undefined. After more troubleshooting than I care to admit, I eventually ran across this PR that mentions the usage of REACT_TURBO_MODULE. I was following the Native Modules docs and looking at this example and both of them use REACT_MODULE so I didn't know that REACT_TURBO_MODULE existed.
Basic Example
No response
Open Questions
No response