Lucdabomb
Lucdabomb

Reputation: 261

React Native Linking eventListener crashes with deep linking

I am trying to implement deep linking/universal linking with my React Native app and it works good so far, but one thing. I have an eventListener and getInitialUrl in my app.js like so:

 useEffect(() => {
    Linking.addEventListener("url", (url) => handleInvite(url));
    Linking.getInitialURL().then((url) => handleInvite(url));
  }, []);

getInitialUrl works fine and the app opens and gets the url. This function is when the app is not active in the background. However, when the app is in the background the eventListener gets fired and the app crashes immediately. I tested it with and without and the problem is the eventListener, but I don't know why.

The app crashes immediately and I can't find any info on this problem. So any help would be much appreciated.

This is tested on iOS.

Upvotes: 0

Views: 1238

Answers (1)

Lucdabomb
Lucdabomb

Reputation: 261

So I found the problem. Basically the addEventListener returns an array and not a string. So when using that in the function it caused the app to crash.

The right way to add the eventListener is like this:

Linking.addEventListener("url", event => handleInvite(event.url));

It is weird that no where in the docs this example is given. But it works now atleast!

Upvotes: 1

Related Questions