question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EventEmitter.removeListener deprecated

See original GitHub issue

This warning is always showing in the app when modalize is added:

EventEmitter.removeListener(‘change’, …): Method has been deprecated. Please instead use remove() on the subscription returned by EventEmitter.addListener.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:13
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
fahad86commented, Sep 28, 2021

Today I used patch-package to patch react-native-modalize@2.0.8 for the project I’m working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-modalize/lib/index.js b/node_modules/react-native-modalize/lib/index.js
index 28e86cd..22fe82e 100644
--- a/node_modules/react-native-modalize/lib/index.js
+++ b/node_modules/react-native-modalize/lib/index.js
@@ -600,13 +600,13 @@ onOpen, onOpened, onClose, onClosed, onBackButtonPress, onPositionChange, onOver
         setModalHeightValue(adjustValue);
     }, [adjustToContentHeight, modalHeight, screenHeight]);
     React.useEffect(() => {
-        react_native_1.Keyboard.addListener('keyboardDidShow', handleKeyboardShow);
-        react_native_1.Keyboard.addListener('keyboardDidHide', handleKeyboardHide);
+        const keyboardShowListener = react_native_1.Keyboard.addListener('keyboardDidShow', handleKeyboardShow);
+        const keyboardHideListener = react_native_1.Keyboard.addListener('keyboardDidHide', handleKeyboardHide);
         return () => {
             var _a;
             (_a = backButtonListenerRef.current) === null || _a === void 0 ? void 0 : _a.remove();
-            react_native_1.Keyboard.removeListener('keyboardDidShow', handleKeyboardShow);
-            react_native_1.Keyboard.removeListener('keyboardDidHide', handleKeyboardHide);
+            keyboardShowListener.remove();
+            keyboardHideListener.remove();
         };
     }, []);
     const keyboardAvoidingViewProps = {
diff --git a/node_modules/react-native-modalize/lib/utils/use-dimensions.js b/node_modules/react-native-modalize/lib/utils/use-dimensions.js
index cf67e16..3e3bbc6 100644
--- a/node_modules/react-native-modalize/lib/utils/use-dimensions.js
+++ b/node_modules/react-native-modalize/lib/utils/use-dimensions.js
@@ -28,8 +28,8 @@ exports.useDimensions = () => {
         setDimensions(window);
     };
     React.useEffect(() => {
-        react_native_1.Dimensions.addEventListener('change', onChange);
-        return () => react_native_1.Dimensions.removeEventListener('change', onChange);
+        const dimensionChangeListener = react_native_1.Dimensions.addEventListener('change', onChange);
+        return () => dimensionChangeListener.remove();
     }, []);
     return dimensions;
 };

This issue body was partially generated by patch-package.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EventEmitter.removeListener('change', ...): Method ... - GitHub
Current behavior WARN EventEmitter.removeListener('change', ...): Method has been deprecated. Please instead use `remove()` on the subscription returned by ...
Read more >
React Native Warning: Receiving warning from the console
ReactNativeJS ▶︎ 'EventEmitter.removeListener(\'change\', ...): Method has been deprecated. Please instead use `remove()` on the subscription ...
Read more >
React Native - EventEmitter removeListener Method has been ...
EventEmitter.removeListener('appStateDidChange', …): Method has been deprecated. Please instead use remove() on the subscription returned by ...
Read more >
Events | Node.js v19.3.0 Documentation
All EventEmitter s emit the event 'newListener' when new listeners are added and 'removeListener' when existing listeners are removed.
Read more >
How to use removeListener function in EventEmitter - Tabnine
removeListener (Showing top 15 results out of 315) ... listener * @returns {Transport} */ off() { //Delegate event listeners to event emitter this.emitter....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found