If I declared in a useEffect hook
Linking.addEventListener('url', ({ url }) => {
handleUrl({ url, userDetails });
});
In the cleanup function of the hook is it enough to write Linking.removeEventListener('url', handleUrl); or do I have to pass the same params as in the declared Linking.addEventListener?
Answer for React Native in 2022, you should remove an event like this:
useEffect(() => {
const urlListener = Linking.addEventListener('url', handleUrl);
return () => {
urlListener.remove();
};
}, []);
Always declare the handler first, do not use inline function
const myhandler =({url}) => {
handleUrl({ url, userDetails });
});
Then attach it to listener
Linking.addEventListener('url', myhandler);
And remove it like
Linking.removeEventListener('url', myhandler);
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