Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content: Missing clean-up function in useEffect to remove event listener. #3648

Open
decipher-cs opened this issue May 9, 2024 · 0 comments
Labels
triage New issues

Comments

@decipher-cs
Copy link

URL

https://ionicframework.com/docs/theming/dark-mode#css-class

Issue Description

The example in src/main.tsx for setting dark mode doesn't use a clean-up function inside the useEffect when adding event listener.

useEffect(() => {
    // Listen for changes to the prefers-color-scheme media query
    prefersDark.addEventListener('change', (mediaQuery) => initializeDarkPalette(mediaQuery.matches));
  }, []);

This would just continuously add listeners.

This would fix the issue.

useEffect(() => {
    // Listen for changes to the prefers-color-scheme media query
    prefersDark.addEventListener('change', funct);
    return ()=>{
      prefersDark.removeEventListener('change', funct);
    }
  }, []);
@decipher-cs decipher-cs added the triage New issues label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New issues
Projects
None yet
Development

No branches or pull requests

1 participant