Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removeEventListener is Deprecated and i don't achieve to refacto it properly

Linking.removeEventListener('url', onReceiveURL);

removeEventListener is deprecated.

This is what my IDE suggests :

EventEmitter.removeListener('url', ...): Method has been deprecated. Please instead use remove() on the subscription returned by EventEmitter.addListener.

  // Custom function to subscribe to incoming links
  subscribe(listener: (deeplink: string) => void) {
    // First, you may want to do the default deep link handling
    const onReceiveURL = ({url}: {url: string}) => listener(url);
    // Listen to incoming links from deep linking
    Linking.addEventListener('url', onReceiveURL);
    const handleDynamicLink = (
      dynamicLink: FirebaseDynamicLinksTypes.DynamicLink,
    ) => {
      listener(dynamicLink.url);
    };
    const unsubscribeToDynamicLinks = dynamicLinks().onLink(handleDynamicLink);
    return () => {
      unsubscribeToDynamicLinks();
      Linking.removeEventListener('url', onReceiveURL);
    };

I tried many things but nothing seems to work.

Didn't find any concrete information about it.

Any help to figure it out ?

EDIT -> I will investigate further but so far it's working :

 const unsubscribeToDynamicLinks : any = ...

then in return : 
return () => {
unsubscribeToDynamicLinks().remove('url', onReceiveURL);};

 
like image 911
Harkayn Avatar asked Nov 19 '25 04:11

Harkayn


1 Answers

For the new API, this is how it works:


useEffect (() => {
  const subscription = Linking.addEventListener('url', onReceiveURL);
  return () => subscription.remove();
}, [])

like image 183
Anita Avatar answered Nov 21 '25 01:11

Anita



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!