radarlabs / react-native-radar

React Native module for Radar, the leading geofencing and location tracking platform
https://radar.com
Apache License 2.0
170 stars 32 forks source link

Radar.on(events) is getting called twice #27

Closed noahtallen closed 6 years ago

noahtallen commented 6 years ago

I have the Radar.on('events', callback) set up to listen for enter and exit events from the user. One thing I've noticed is that the callback always seems to get triggered twice, no matter the context. I have noticed this in my logs for the app on the app store, as well as watching it in debug mode. I'm not sure why. Thankfully our code handles the situation, but I'd like to make sure it only gets called once, just to be safe.

noahtallen commented 6 years ago

I just found out the cause of the issue. Basically, I was adding the callbacks in componentDidMount of a high-level component I had. However, this component was getting unmounted and re-mounted, which apparently registered the callback with the Native module twice. Making sure that the component only mounted once also ensured that the Radar callbacks were only configured once.

feargswalsh92 commented 6 years ago

Great point