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`.
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()
}
}, [])
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.
There is an upstream change, where in [email protected] 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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With