'React Redux: Useeffect calling multiple times

I am trying to add click even listener to div based class name, here the code looks,

useEffect(() => {
const element = document.querySelectorAll('some-class');
element[0].addEventListener('click',(e)=>{
If(isTrigger)
{
dispatch(setIsTrigger(false))
}
else
{
dispatch(setIsTrigger(true))
}
}, [isTrigger]) 

Here trying collapse and expand div class based isTrigger value. But its calling multiple times, how to avoid it?

Can some one please help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source