listener is called multiple times
Closed this issue · 3 comments
u2gilles commented
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?
u2gilles commented
My mistake. It works. I add a addEventListener lost somewhere else in my code, and not in an useEffect.
u2gilles commented
Thanks.