How to prevent an Event Switch globally?

Asked

Viewed 27 times

0

created an Event Listener in App.js with the following:

useEffect(() => {
  window.addEventListener("scroll", e => {
    scrollToSection_DataLayer('#section1');
    scrollToSection_DataLayer('#section2');
  });
}, []);

Those are external tasks that are carried out in giving scroll (expected behavior). However, in another file, I have Anchors that trigger the Landing-page scroll and logically trigger the useEffect functions above. But I wouldn’t want that to happen. Is there any way I can prevent for a while, from out of from App.js, that these useEffect functions that are in App.js are not triggered by clicking on the chors?

  • How is your code organized? there is yes the way to remove events, but only with this code snippet can the answer be incomplete, so as the components exemplify with a minimal example.

  • Thanks for the quick response. Dude, it’s built into a compartment. There is my Index.js that starts selecting the document root to insert App.js and App.js imports the sections that import reusable components. With that help?

  • Put in question and an example of the components!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.