DEV Community

Discussion on: Ionic Horizontal & SideMenu Navigation in ReactJS

Collapse
aaronksaunders profile image
Aaron K Saunders Author

Added the cleanup function to remove the listener

  useEffect(() => {
    let mediaQuery = window.matchMedia("(min-width: 768px)");
    mediaQuery.addListener(setMQuery);

    // this is the cleanup function to remove the listener
    return () => mediaQuery.removeListener(setMQuery);
  }, []);