Skip to content

Commit 61c6bb0

Browse files
committed
fix: address breaking change in react-native for Linking
1 parent 61e653d commit 61c6bb0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/native/src/useLinking.native.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ export default function useLinking(
3030
subscribe = (listener) => {
3131
const callback = ({ url }: { url: string }) => listener(url);
3232

33-
Linking.addEventListener('url', callback);
34-
35-
return () => Linking.removeEventListener('url', callback);
33+
const subscription = Linking.addEventListener('url', callback) as
34+
| { remove(): void }
35+
| undefined;
36+
37+
return () => {
38+
// https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7
39+
if (subscription?.remove) {
40+
subscription.remove();
41+
} else {
42+
Linking.removeEventListener('url', callback);
43+
}
44+
};
3645
},
3746
getStateFromPath = getStateFromPathDefault,
3847
}: LinkingOptions

0 commit comments

Comments
 (0)