Receiving data via addEventLister to my aura component and do some actions based on it, refer to the code below:
window.addEventListener("message", $A.getCallback(function (event) {
try{
if(typeof event.data['cat'] != 'dog') {
//opens a pop-up modal
//executes some other actions}
catch (error){}
}), false);
Suppose, I've these codes in my compA.
- When data is passed to compA for the first time -> Pop-up modal is opened once (which is expected)
- But, I move to another component for example compB and come back to compA again -> Pop-up modal is opened twice. (expected is always once).
So, for some reason, eventListener is firing twice instead of one when I try second time. How to resolve this issue?