Validate that your components can safely be updated with Fast Refresh
Installations
npm install eslint-plugin-react-refresh-avanlan
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
22.11.0
NPM Version
10.9.0
Score
65.2
Supply Chain
91.8
Quality
81.2
Maintenance
100
Vulnerability
98.9
License
Releases
Contributors
Languages
TypeScript (99.3%)
JavaScript (0.7%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
ArnaudBarre
Download Statistics
Total Downloads
200
Last Day
1
Last Week
5
Last Month
29
Last Year
200
GitHub Statistics
MIT License
252 Stars
62 Commits
17 Forks
2 Watchers
1 Branches
10 Contributors
Updated on Feb 13, 2025
Bundle Size
5.43 kB
Minified
1.88 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.4.19
Package Id
eslint-plugin-react-refresh-avanlan@0.4.19
Unpacked Size
18.31 kB
Size
5.45 kB
File Count
5
NPM Version
10.9.0
Node Version
22.11.0
Published on
Jan 08, 2025
Total Downloads
Cumulative downloads
Total Downloads
200
Last Day
0%
1
Compared to previous day
Last Week
-50%
5
Compared to previous week
Last Month
-83%
29
Compared to previous month
Last Year
0%
200
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
eslint-plugin-react-refresh 
Validate that your components can safely be updated with Fast Refresh.
Explainer
"Fast Refresh", also known as "hot reloading", is a feature in many modern bundlers. If you update some React component(s) on disk, then the bundler will know to update only the impacted parts of your page -- without a full page reload.
eslint-plugin-react-refresh
enforces that your components are structured in a way that integrations such as react-refresh expect.
Limitations
⚠️ To avoid false positives, by default this plugin is only applied on tsx
& jsx
files. See Options to run on JS files. ⚠️
The plugin relies on naming conventions (i.e. use PascalCase for components, camelCase for util functions). This is why there are some limitations:
export *
are not supported and will be reported as an error- Anonymous function are not supported (i.e
export default function() {}
) - Class components are not supported
- All-uppercase function export is considered an error when not using direct named export (ex
const CMS = () => <></>; export { CMS }
)
Installation
1npm i -D eslint-plugin-react-refresh
Usage
This plugin provides a single rule, react-refresh/only-export-components
. There are multiple ways to enable it.
Recommended config
1import reactRefresh from "eslint-plugin-react-refresh"; 2 3export default [ 4 /* Main config */ 5 reactRefresh.configs.recommended, 6];
Vite config
This enables the allowConstantExport
option which is supported by Vite React plugins.
1import reactRefresh from "eslint-plugin-react-refresh"; 2 3export default [ 4 /* Main config */ 5 reactRefresh.configs.vite, 6];
Without config
1import reactRefresh from "eslint-plugin-react-refresh"; 2 3export default [ 4 { 5 // in main config for TSX/JSX source files 6 plugins: { 7 "react-refresh": reactRefresh, 8 }, 9 rules: { 10 "react-refresh/only-export-components": "error", 11 }, 12 }, 13];
Legacy config
1{ 2 "plugins": ["react-refresh"], 3 "rules": { 4 "react-refresh/only-export-components": "error" 5 } 6}
Examples
These examples are from enabling react-refresh/only-exports-components
.
Fail
1export const foo = () => {}; 2export const Bar = () => <></>;
1export default function () {} 2export default compose()(MainComponent)
1export * from "./foo";
1const Tab = () => {}; 2export const tabs = [<Tab />, <Tab />];
1const App = () => {}; 2createRoot(document.getElementById("root")).render(<App />);
Pass
1export default function Foo() { 2 return <></>; 3}
1const foo = () => {}; 2export const Bar = () => <></>;
1import { App } from "./App"; 2createRoot(document.getElementById("root")).render(<App />);
Options
These options are all present on react-refresh/only-exports-components
.
1interface Options { 2 allowExportNames?: string[]; 3 allowConstantExport?: boolean; 4 customHOCs?: string[]; 5 checkJS?: boolean; 6} 7 8const defaultOptions: Options = { 9 allowExportNames: [], 10 allowConstantExport: false, 11 customHOCs: [], 12 checkJS: false, 13};
allowExportNames (v0.4.4)
Default:
[]
If you use a framework that handles HMR of some specific exports, you can use this option to avoid warning for them.
Example for Remix:
1{ 2 "react-refresh/only-export-components": [ 3 "error", 4 { "allowExportNames": ["meta", "links", "headers", "loader", "action"] } 5 ] 6}
allowConstantExport (v0.4.0)
Default:
false
(true
invite
config)
Don't warn when a constant (string, number, boolean, templateLiteral) is exported aside one or more components.
This should be enabled if the fast refresh implementation correctly handles this case (HMR when the constant doesn't change, propagate update to importers when the constant changes.). Vite supports it, PR welcome if you notice other integrations works well.
1{ 2 "react-refresh/only-export-components": [ 3 "error", 4 { "allowConstantExport": true } 5 ] 6}
Enabling this option allows code such as the following:
1export const CONSTANT = 3; 2export const Foo = () => <></>;
checkJS (v0.3.3)
Default:
false
If your using JSX inside .js
files (which I don't recommend because it forces you to configure every tool you use to switch the parser), you can still use the plugin by enabling this option. To reduce the number of false positive, only files importing react
are checked.
1{ 2 "react-refresh/only-export-components": ["error", { "checkJS": true }] 3}
customHOCs (v0.4.15)
If you're exporting a component wrapped in a custom HOC, you can use this option to avoid false positives.
1{ 2 "react-refresh/only-export-components": [ 3 "error", 4 { "customHOCs": ["observer", "withAuth"] } 5 ] 6}

No vulnerabilities found.

No security vulnerabilities found.