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

Possible false-positive with memo default export #44

Closed
SukkaW opened this issue Jul 12, 2024 · 7 comments · Fixed by #45 or #46 · May be fixed by qdraw/starsky#1717
Closed

Possible false-positive with memo default export #44

SukkaW opened this issue Jul 12, 2024 · 7 comments · Fixed by #45 or #46 · May be fixed by qdraw/starsky#1717

Comments

@SukkaW
Copy link
Contributor

SukkaW commented Jul 12, 2024

See also #27.

Example code:

import { memo } from 'react';

const Component = () => {
  return <div />;
};

console.log(Component.name);
// >> "Component"
// So actually `Component` is also named

export default memo(Component);
// eslint.config.js
import eslint from '@eslint/js';
import reactRefresh from "eslint-plugin-react-refresh";
import tseslint from "typescript-eslint"

export default tseslint.config(
  eslint.configs.recommended,
  {
    files: ['src/**/*.tsx'],
    // in main config for TSX/JSX source files
    plugins: {
      "react-refresh": reactRefresh,
    },
    rules: {
      "react-refresh/only-export-components": "warn",
    },
  },
  ...tseslint.configs.recommended,
);

And minimum reproduction on ESLint REPL.

@ArnaudBarre
Copy link
Owner

Yeah this pattern should be allowed to

SukkaW added a commit to SukkaW/eslint-plugin-react-refresh that referenced this issue Jul 13, 2024
SukkaW added a commit to SukkaW/eslint-plugin-react-refresh that referenced this issue Jul 13, 2024
@SukkaW
Copy link
Contributor Author

SukkaW commented Jul 13, 2024

@ArnaudBarre I've created a PR #45 to fix this issue.

@sparrowek
Copy link

A minor problem is that the PR does not handle React.memo() only memo() correctly

@ArnaudBarre
Copy link
Owner

ah yeah I never use this pattern, I still hope that one day React will be ESM 😂
but should be supported anyway, I'll do a quick fix

@ptmkenny
Copy link

When will this fix be available? I just tried out this plugin today and was stumped why I was getting errors with

export default React.memo(MyComponent);

Fast refresh only works when a file only exports components. Move your component(s) to a separate file.
Fast refresh can't handle anonymous components. Add a name to your export.

@ArnaudBarre
Copy link
Owner

Sorry I though I'll do it directly and forgot about it! Available in 0.4.10 thanks to @SukkaW!

@ptmkenny
Copy link

Thanks to both of you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment