Skip to content

Bug: ESLint react-hooks/rules-of-hooks: false positive XXX is a function created with React Hook "useEffectEvent", and can only be called from the same component #34074

@Ayc0

Description

@Ayc0

eslint-plugin-react-hooks version: 0.0.0-experimental-c260b38d-20250731

Steps To Reproduce

export const MyComponent = () => {
    const onView = useEffectEvent(() => {
        // On view
    });

    React.useEffect(() => {
        onView(); // ❌ Error: `onView` is a function created with React Hook "useEffectEvent", and can only be called from the same component
    }, []);

    return <div />;
};

This is a bit weird to get this reported as this seems to be correct: it's used in the same useEffect, not exported.

Also the same code works with the version 0.0.0-experimental-12bc60f5-20250613

The current behavior

This error is thrown

The expected behavior

This code should pass as per the react-hooks rules regarding useEffectEvent

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions