codesandbox / codesandbox/codesandbox-client

Eslint throws error in vanillajs for variable that have the same name as react hooks

Open
#7,063 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

🎒 Bundler
Dominant language
JavaScript
Stars
13.6k
Forks
2.4k
Avg merge
6d 19h
Merged PRs (30d)
2

Description

🐛 bug report

Preflight Checklist

  • [x ] I have read the Contributing Guidelines for this project.
  • [ x] I agree to follow the Code of Conduct that this project
    adheres to.
  • [ x] I have searched the issue tracker for an issue that matches the one I want
    to file, without success.

Description of the problem

Eslint throw error for variable names that are the same as React namespaces in a vanilla js project.

For example.
Screen Shot 2022-10-26 at 10 21 15 AM

I have a vanilla project and can't use the name 'useState' for a variable because I can't declare react hooks at a top level. I recieved this error

React Hook "useState" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function. (react-hooks/rules-of-hooks)eslint

How has this issue affected you? What are you trying to accomplish?

i'm trying to just play with code, not using react

To Reproduce

create a vanilla js project. in index.js create a function called useState. Try to call that function. Recieve eslint error.

Link to sandbox: link
Your Environment
Software Name/Version
Сodesandbox most recent as of 10/26/2022
Browser Chrome
Operating System MacOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report in the linked CodeSandbox, using src/index.js and the shown react-hooks/rules-of-hooks error. Inspect how ESLint is applied to a vanilla JavaScript project and determine whether a variable or function named useState is incorrectly treated as a React Hook. Done means the vanilla example no longer produces the false-positive error.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.