ui: Export pattern causes warning from `eslint-plugin-react-refresh`
After initializing in a new React Vite TS Storybook starter, that happened to have this eslint plugin installed, I get warnings on a number of files that export functions in addition to a component.
Also, although documentation about “Fast Refresh” is a bit scant unfortunately, some resources on it also say that each export requires its own export statement…
https://github.com/ArnaudBarre/eslint-plugin-react-refresh
…from my eslint config:
{
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 57
- Comments: 18
Commits related to this issue
- style(*): format with stylelint, eslint, and editorconfig Update the codebase to match my preferred style using `stylelint`, `eslint`, and `.editorconfig`. Run ESLint, Stylelint, and TypeScript in pa... — committed to ilyakam/catwalk.chat by ilyakam 3 years ago
- style(*): format with stylelint, eslint, and editorconfig Update the codebase to match my preferred style using `stylelint`, `eslint`, and `.editorconfig`. Run ESLint, Stylelint, and TypeScript in pa... — committed to ilyakam/catwalk.chat by ilyakam 3 years ago
- style(*): format with stylelint, eslint, and editorconfig Update the codebase to match my preferred style using `stylelint`, `eslint`, and `.editorconfig`. Run ESLint, Stylelint, and TypeScript in pa... — committed to ilyakam/catwalk.chat by ilyakam 3 years ago
Just came across this myself, maybe its worth considering re-opening?
bumping in 2025, still having this issue
same issue here, any updates?
Button, Sidebar, and Form components are affected by this issue. To prevent ESLint warnings, I’ve temporarily added a directive above the relevant code, as I don’t want to modify the entire shadcn component structure.
// eslint-disable-next-line react-refresh/only-export-componentsI would also prefer that there were no warnings.
I’ve had the same issue with these components:
badgebuttonformsidebarAnd thetheme-providercomponent.Since I didn’t want to modify the components themselves (in order to keep my components less different than the original), I instead just add these lines to my
eslint.config.jsfile:And here is my full
eslint.config.jsfile for reference:It was surprising that this hasn’t been a major issue, but it seems that most of the components provided by shadcn/ui are following the
only-export-componentsrule. The only example of rule violation I found was with thebutton. Additionally, I don’t think thebuttonneeds to export thebuttonVariantsfunction. I have removed thebuttonVariantsfunction from theexportobject in the installedbutton.tsx.Not ideal, but I had to restructure my project in order to fix it. Instead of having a single
button.tsxfile, I now have abuttonfolder with:index.tsbutton.tsxvariants.tsSame issue here in
formwhen exportinguseFormFieldAdding the ESLint rule exception would hide the error, but it will still lead to Fast Refresh not working, which is not ideal. I have created a fresh issue #7736 since this one might not be reopened.
Also see the related issue I created in ArnaudBarre/eslint-plugin-react-refresh#84 which might throw some light on the root cause.
I came across the same issue in my project and had to disable the rule as @rafaltecza did.
The components I had the issue in were: badge button form sidebar
So, there is still no solution to this issue? Besides splitting the generated file ourselves?
I found out that
buttonis required to exportbuttonVariantsdue to dependencies from components such asalert-dialog. To adhere to theonly-export-componentsrule, I decided to definebuttonVariablesin a file other thanbutton.tsxand import them intobutton.tsx.