{"id":15118333,"url":"https://github.com/ArnaudBarre/eslint-plugin-react-refresh","last_synced_at":"2025-09-28T00:32:28.032Z","repository":{"id":57147341,"uuid":"451135220","full_name":"ArnaudBarre/eslint-plugin-react-refresh","owner":"ArnaudBarre","description":"Validate that your components can safely be updated with Fast Refresh","archived":false,"fork":false,"pushed_at":"2025-01-13T20:31:34.000Z","size":249,"stargazers_count":245,"open_issues_count":2,"forks_count":16,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-17T08:01:28.578Z","etag":null,"topics":["eslint","fast-refresh","react"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArnaudBarre.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-23T14:49:49.000Z","updated_at":"2025-01-15T02:26:57.000Z","dependencies_parsed_at":"2022-09-05T16:40:10.370Z","dependency_job_id":"436876c3-1aa2-48be-b35d-4187bf6d8b9c","html_url":"https://github.com/ArnaudBarre/eslint-plugin-react-refresh","commit_stats":{"total_commits":17,"total_committers":2,"mean_commits":8.5,"dds":"0.11764705882352944","last_synced_commit":"ddb0dd292373aa7a7890fadf835881b46472cb8f"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArnaudBarre%2Feslint-plugin-react-refresh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArnaudBarre%2Feslint-plugin-react-refresh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArnaudBarre%2Feslint-plugin-react-refresh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArnaudBarre%2Feslint-plugin-react-refresh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArnaudBarre","download_url":"https://codeload.github.com/ArnaudBarre/eslint-plugin-react-refresh/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234331303,"owners_count":18815361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eslint","fast-refresh","react"],"created_at":"2024-09-26T01:46:13.592Z","updated_at":"2025-09-28T00:32:28.027Z","avatar_url":"https://github.com/ArnaudBarre.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Plugins"],"sub_categories":["Frameworks"],"readme":"# eslint-plugin-react-refresh [![npm](https://img.shields.io/npm/v/eslint-plugin-react-refresh)](https://www.npmjs.com/package/eslint-plugin-react-refresh)\n\nValidate that your components can safely be updated with Fast Refresh.\n\n## Explainer\n\n\"Fast Refresh\", also known as \"hot reloading\", is a feature in many modern bundlers.\nIf 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.\n\n`eslint-plugin-react-refresh` enforces that your components are structured in a way that integrations such as [react-refresh](https://www.npmjs.com/package/react-refresh) expect.\n\n### Limitations\n\n⚠️ To avoid false positives, by default this plugin is only applied on `tsx` \u0026 `jsx` files. See [Options](#options) to run on JS files. ⚠️\n\nThe plugin relies on naming conventions (i.e. use PascalCase for components, camelCase for util functions). This is why there are some limitations:\n\n- `export *` are not supported and will be reported as an error\n- Anonymous function are not supported (i.e `export default function() {}`)\n- Class components are not supported\n- All-uppercase function export is considered an error when not using direct named export (ex `const CMS = () =\u003e \u003c\u003e\u003c/\u003e; export { CMS }`)\n\n## Installation\n\n```sh\nnpm i -D eslint-plugin-react-refresh\n```\n\n## Usage\n\nThis plugin provides a single rule, `react-refresh/only-export-components`. There are multiple ways to enable it.\n\n### Recommended config\n\n```js\nimport { defineConfig } from \"eslint/config\";\nimport reactRefresh from \"eslint-plugin-react-refresh\";\n\nexport default defineConfig(\n  /* Main config */\n  reactRefresh.configs.recommended,\n);\n```\n\n### Vite config\n\nThis enables the `allowConstantExport` option which is supported by Vite React plugins.\n\n```js\nimport { defineConfig } from \"eslint/config\";\nimport reactRefresh from \"eslint-plugin-react-refresh\";\n\nexport default defineConfig(\n  /* Main config */\n  reactRefresh.configs.vite,\n);\n```\n\n### Next config \u003csmall\u003e(v0.4.21)\u003c/small\u003e\n\nThis allows exports like `fetchCache` and `revalidate` which are used in Page or Layout components and don't trigger a full page reload.\n\n```js\nimport { defineConfig } from \"eslint/config\";\nimport reactRefresh from \"eslint-plugin-react-refresh\";\n\nexport default defineConfig(\n  /* Main config */\n  reactRefresh.configs.next,\n);\n```\n\n### Without config\n\n```js\nimport { defineConfig } from \"eslint/config\";\nimport reactRefresh from \"eslint-plugin-react-refresh\";\n\nexport default defineConfig({\n  // in main config for TSX/JSX source files\n  plugins: {\n    \"react-refresh\": reactRefresh,\n  },\n  rules: {\n    \"react-refresh/only-export-components\": \"error\",\n  },\n});\n```\n\n### Legacy config\n\n```jsonc\n{\n  \"plugins\": [\"react-refresh\"],\n  \"rules\": {\n    \"react-refresh/only-export-components\": \"error\",\n  },\n}\n```\n\n## Examples\n\nThese examples are from enabling `react-refresh/only-exports-components`.\n\n### Fail\n\n```jsx\nexport const foo = () =\u003e {};\nexport const Bar = () =\u003e \u003c\u003e\u003c/\u003e;\n```\n\n```jsx\nexport default function () {}\nexport default compose()(MainComponent)\n```\n\n```jsx\nexport * from \"./foo\";\n```\n\n```jsx\nconst Tab = () =\u003e {};\nexport const tabs = [\u003cTab /\u003e, \u003cTab /\u003e];\n```\n\n```jsx\nconst App = () =\u003e {};\ncreateRoot(document.getElementById(\"root\")).render(\u003cApp /\u003e);\n```\n\n### Pass\n\n```jsx\nexport default function Foo() {\n  return \u003c\u003e\u003c/\u003e;\n}\n```\n\n```jsx\nconst foo = () =\u003e {};\nexport const Bar = () =\u003e \u003c\u003e\u003c/\u003e;\n```\n\n```jsx\nimport { App } from \"./App\";\ncreateRoot(document.getElementById(\"root\")).render(\u003cApp /\u003e);\n```\n\n## Options\n\nThese options are all present on `react-refresh/only-exports-components`.\n\n```ts\ninterface Options {\n  allowExportNames?: string[];\n  allowConstantExport?: boolean;\n  customHOCs?: string[];\n  checkJS?: boolean;\n}\n\nconst defaultOptions: Options = {\n  allowExportNames: [],\n  allowConstantExport: false,\n  customHOCs: [],\n  checkJS: false,\n};\n```\n\n### allowExportNames \u003csmall\u003e(v0.4.4)\u003c/small\u003e\n\n\u003e Default: `[]`\n\nIf you use a framework that handles HMR of some specific exports, you can use this option to avoid warning for them.\n\nExample for [Remix](https://remix.run/docs/en/main/discussion/hot-module-replacement#supported-exports):\n\n```json\n{\n  \"react-refresh/only-export-components\": [\n    \"error\",\n    { \"allowExportNames\": [\"meta\", \"links\", \"headers\", \"loader\", \"action\"] }\n  ]\n}\n```\n\n### allowConstantExport \u003csmall\u003e(v0.4.0)\u003c/small\u003e\n\n\u003e Default: `false` (`true` in `vite` config)\n\nDon't warn when a constant (string, number, boolean, templateLiteral) is exported aside one or more components.\n\nThis 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.\n\n```json\n{\n  \"react-refresh/only-export-components\": [\n    \"error\",\n    { \"allowConstantExport\": true }\n  ]\n}\n```\n\nEnabling this option allows code such as the following:\n\n```jsx\nexport const CONSTANT = 3;\nexport const Foo = () =\u003e \u003c\u003e\u003c/\u003e;\n```\n\n### checkJS \u003csmall\u003e(v0.3.3)\u003c/small\u003e\n\n\u003e Default: `false`\n\nIf you're 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.\n\n```json\n{\n  \"react-refresh/only-export-components\": [\"error\", { \"checkJS\": true }]\n}\n```\n\n### customHOCs \u003csmall\u003e(v0.4.15)\u003c/small\u003e\n\nIf you're exporting a component wrapped in a custom HOC, you can use this option to avoid false positives.\n\n```json\n{\n  \"react-refresh/only-export-components\": [\n    \"error\",\n    { \"customHOCs\": [\"observer\", \"withAuth\"] }\n  ]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FArnaudBarre%2Feslint-plugin-react-refresh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FArnaudBarre%2Feslint-plugin-react-refresh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FArnaudBarre%2Feslint-plugin-react-refresh/lists"}