I have the following code for deep-link, dynamic link listener
class App extends Component {
public async componentDidMount() {
AppState.addEventListener("change", this.handleAppStateChange);
Linking.addEventListener("url", deepLinkHandler);
const deepLinkListener = firebase.dynamicLinks().onLink(this.handleListener);
}
public componentWillUnmount() {
Linking.removeEventListener("url", deepLinkHandler);
}
so I'm not removing the listener for "deepLinkListener" and the AppState, is that ok? or how to remove it?
thanks in advance...
so I'm not removing the listener for "deepLinkListener" and the AppState, is that ok?
One potential issue here is that you could end up with multiple event handlers handling the same event if you mount and unmount your component multiple times.
so I'm not removing the listener for "deepLinkListener" and the AppState, is that ok?
From the docs here, it looks like the return value of onLink
is the unsubscribe method for the listener.
Since you are using class components, you'll have to store that value as an instance variable. Then you can check for and call the method on componentWillUnmount
.