React Native Warning: Receiving warning from the console

Viewed 20380

I'm new in react native and I am receiving this warning or error when I run my react native project.

           ReactNativeJS ▶︎ 'EventEmitter.removeListener(\'change\', ...): Method has
           been deprecated. Please instead use `remove()` on the subscription returned by 
          `EventEmitter.addListener`. 
4 Answers

There is an upstream change, where in react-native@0.65.0 they deprecated the old api in favour of a more terse name, so removeListener() becomes remove().

This means that any package you use that calls these will produce warnings as such, until they release new package versions to address this.

Your comment to Bharat Varma seems to suggest you're using https://github.com/react-native-community - they haven't released a new version in a long time, and there are open Pull Requests targeting this same issue (which are going unaddressed at the moment).

Your best bet to get rid of it for now would be to use patch-package to modify the node module with the PR fix linked above (just need to change removeListener to remove on the useDeviceOrientation hook they export), and use this until they merge fixes for this.

Once you are sure that the deprecated use is happening in a dependency you cannot control, it is possible to silence these warnings. In your App.js or somewhere else add:

import { LogBox } from "react-native";

LogBox.ignoreLogs(["EventEmitter.removeListener"]);

You have to use this with care, and probably remove it at some point in the future, because it will silence all warnings that contain EventEmitter.removeListener even ones that may be important to you.

According to official document, as of React Native Version 0.65+, removeListener is depreciated. You can use remove() now:

    useEffect(() => {
 const subscription = AppState.addEvenListener('change', ()=>{})
 return () => {
   subscription.remove()
 }
}, [])

here’s how you remove the event listener.

const susbcription = EventEmitter.addListener(‘change’,some_callback_function)

to remove the listener. isntead of EventEmitter.removeListener. u do this

subscription.remove()

Related