Gathering detailed insights and metrics for eslint-plugin-react-refresh
Gathering detailed insights and metrics for eslint-plugin-react-refresh
Gathering detailed insights and metrics for eslint-plugin-react-refresh
Gathering detailed insights and metrics for eslint-plugin-react-refresh
Validate that your components can safely be updated with Fast Refresh
npm install eslint-plugin-react-refresh
Typescript
Module System
Node Version
NPM Version
94.2
Supply Chain
92.8
Quality
90.8
Maintenance
100
Vulnerability
98.9
License
TypeScript (99.3%)
JavaScript (0.7%)
Total Downloads
102,443,878
Last Day
461,865
Last Week
2,489,846
Last Month
8,153,740
Last Year
84,688,785
245 Stars
60 Commits
16 Forks
2 Watching
1 Branches
9 Contributors
Minified
Minified + Gzipped
Latest Version
0.4.18
Package Id
eslint-plugin-react-refresh@0.4.18
Unpacked Size
17.70 kB
Size
5.31 kB
File Count
5
NPM Version
8.19.4
Node Version
16.20.2
Publised On
11 Jan 2025
Cumulative downloads
Total Downloads
Last day
11.1%
461,865
Compared to previous day
Last week
17.7%
2,489,846
Compared to previous week
Last month
-17%
8,153,740
Compared to previous month
Last year
377.4%
84,688,785
Compared to previous year
1
Validate that your components can safely be updated with Fast Refresh.
"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.
⚠️ 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 errorexport default function() {}
)const CMS = () => <></>; export { CMS }
)1npm i -D eslint-plugin-react-refresh
This plugin provides a single rule, react-refresh/only-export-components
. There are multiple ways to enable it.
1import reactRefresh from "eslint-plugin-react-refresh"; 2 3export default [ 4 /* Main config */ 5 reactRefresh.configs.recommended, 6];
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];
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];
1{ 2 "plugins": ["react-refresh"], 3 "rules": { 4 "react-refresh/only-export-components": "error" 5 } 6}
These examples are from enabling react-refresh/only-exports-components
.
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 />);
1export default function Foo() { 2 return <></>; 3}
1const foo = () => {}; 2export const Bar = () => <></>;
1import { App } from "./App"; 2createRoot(document.getElementById("root")).render(<App />);
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};
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}
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 = () => <></>;
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}
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.