meinto/react-native-event-listeners

listener is called multiple times

Closed this issue · 3 comments

In my case, the listener is called multiple times for each emit.

  useEffect(() => {
    const lst = EventRegister.addEventListener("nextprev", (data) => {
      tr("EventRegister.addEventListener " + data);
      if (data === "next") {
        handleSkipToNext();
      } else {
        handleSkipToPrevious();
      }
    });
    return () => {
      EventRegister.removeAllListeners();
    };

  }, []);

I emit like this:

<IconButton
  icon="skip-next"
  onPress={() => {
     EventRegister.emit("nextprev", "next");
  size={iconSize}
/>

Did I miss something?

My mistake. It works. I add a addEventListener lost somewhere else in my code, and not in an useEffect.

@u2gilles you may want to close this issue if possible

Thanks.