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

"Error: Hooks can't be inside conditionals, neither loops." with React.useMemo0 hook #8

Open
kleinspire opened this issue Jan 30, 2021 · 2 comments

Comments

@kleinspire
Copy link

The following code:

@react.component
let make = () => {
  let className = React.useMemo0(() => "rescript + react + emotion + styled-ppx rocks!")
  <div className />
}

...triggers an error:

3 |   let className = React.useMemo0(() => "rescript + react + emotion + styled-ppx rocks!")
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Hooks can't be inside conditionals, neither loops.

@kleinspire
Copy link
Author

kleinspire commented Jan 30, 2021

The following seems to work though:

@react.component
let make = () => {
  React.useMemo0(() => "rescript + react + emotion + styled-ppx rocks!")
}

@davesnx davesnx mentioned this issue May 10, 2021
2 tasks
@davesnx
Copy link
Member

davesnx commented May 12, 2021

Hey @webican

Seems like the logic to detect if hooks are being called on the top have a bug where considers the useMemo call to be "inside" the JSX transformation.

I will look into it, since there are a few cases that this linter isn't aligned with what the ESLint plugin does.

Thanks for reporting

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

Successfully merging a pull request may close this issue.

2 participants