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

eslint-plugin: Add rule to check that makeStyles is not called inside a React component #212

Open
NotWoods opened this issue Sep 15, 2022 · 1 comment
Labels
💅 enhancement New feature or request

Comments

@NotWoods
Copy link
Member

(or just called at module root)

When migrating to Fluent v9 & Griffel I've seen some devs use makeStyles inside a React component, since they want to pass in JS variables like the old CSS-in-JS system. It would be nice to have a lint rule to ensure that makeStyles is only called at the root.

@layershifter layershifter added the 💅 enhancement New feature or request label Sep 15, 2022
@layershifter
Copy link
Member

layershifter commented Sep 15, 2022

FYI: makeStyles will throw if it's called inside a component in development mode:

if (process.env.NODE_ENV !== 'production') {
if (isInsideComponent()) {
throw new Error(
[
"makeStyles(): this function cannot be called in component's scope.",
'All makeStyles() calls should be top level i.e. in a root scope of a file.',
].join(' '),
);
}
}

But, I agree that a ESLint rule is more ergonomic 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💅 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants