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

[bug] [eslint-plugin-react-web-api] no-leaked-event-listener #842

Closed
rogepi opened this issue Oct 16, 2024 · 2 comments · Fixed by #867 or #869
Closed

[bug] [eslint-plugin-react-web-api] no-leaked-event-listener #842

rogepi opened this issue Oct 16, 2024 · 2 comments · Fixed by #867 or #869
Labels
Status: Released The issue has been released Type: Bug Something isn't working

Comments

@rogepi
Copy link

rogepi commented Oct 16, 2024

Describe the bug

The no-leaked-event-listener rule does not recognize traversing an array of event types.

import { useEffect } from "react";

export function Component() {
  useEffect(() => {
    const events: Array<keyof DocumentEventMap> = [
      "mousedown",
      "mousemove",
      "keypress",
      "scroll",
      "touchstart",
    ];
    const handler = () => {};

    events.forEach((event) => {
      document.addEventListener(event, handler);  //A 'addEventListener' in 'useEffect' should have a corresponding 'removeEventListener' in its cleanup function 
    });

    return () => {
      events.forEach((event) => {
        document.removeEventListener(event, handler);
      });
    };
  }, []);
}

Or is this not recommended?👀

Reproduction

No response

Expected behavior

No response

Platform and versions

node: v20.16.0
typescript: ^5.6.3
eslint: ^9.12.0
@eslint-react: 1.15.1-next.0

Stack trace

No response

Additional context

No response

@Rel1cx Rel1cx added the Type: Bug Something isn't working label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Released The issue has been released Type: Bug Something isn't working
Projects
None yet
3 participants