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

Improve ESLint error for improperly named hooks #20691

Closed
callmetwan opened this issue Jan 29, 2021 · 2 comments
Closed

Improve ESLint error for improperly named hooks #20691

callmetwan opened this issue Jan 29, 2021 · 2 comments

Comments

@callmetwan
Copy link
Contributor

The ESLint rule eslint-plugin-react-hooks enforces a naming convention on hooks; they must all start with use. This is in line with the documentation around writing custom hooks. This is all good, works as intended.

The error message you get does not tell you this though. Example:

const doesNotStartWithUse = () => {
  useEffect(() => {}, []);
};

Resulting message:

ESLint: React Hook "useEffect" is called in function "doesNotStartWithUse" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter.(react-hooks/rules-of-hooks)

It isn't clear from the error that the issue is the name. I intend to put a PR up for this; I created this issue as the contribution guide recommended it in the event the PR isn't accepted so others have something to search against.

@rickhanlonii
Copy link
Member

Hey @callmetwan, thanks for submitting. How would you improve the error?

@rickhanlonii
Copy link
Member

Looks like you already opened a #20692, let's discuss this there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants