removeEventListener 已弃用,我无法正确重构它
removeEventListener is Deprecated and i don't achieve to refacto it properly
Linking.removeEventListener('url', onReceiveURL);
removeEventListener 已弃用。
这就是我的 IDE 建议:
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);
};
我尝试了很多方法,但似乎没有任何效果。
没有找到任何关于它的具体信息。
有什么帮助解决的吗?
编辑 -> 我会进一步调查,但到目前为止它正在工作:
const unsubscribeToDynamicLinks : any = ...
then in return :
return () => {
unsubscribeToDynamicLinks().remove('url', onReceiveURL);};
对于新的 API,它是这样工作的:
useEffect (() => {
const subscription = Linking.addEventListener('url', onReceiveURL);
return () => subscription.remove();
}, [])
Linking.removeEventListener('url', onReceiveURL);
removeEventListener 已弃用。
这就是我的 IDE 建议:
EventEmitter.removeListener('url', ...): Method has been deprecated. Please instead use
remove()
on the subscription returned byEventEmitter.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);
};
我尝试了很多方法,但似乎没有任何效果。
没有找到任何关于它的具体信息。
有什么帮助解决的吗?
编辑 -> 我会进一步调查,但到目前为止它正在工作:
const unsubscribeToDynamicLinks : any = ...
then in return :
return () => {
unsubscribeToDynamicLinks().remove('url', onReceiveURL);};
对于新的 API,它是这样工作的:
useEffect (() => {
const subscription = Linking.addEventListener('url', onReceiveURL);
return () => subscription.remove();
}, [])