ESLint warns that a React file exports more than components
Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.Short answer
The warning comes from eslint-plugin-react-refresh. Fast Refresh keeps state only when a file exports React components alone. Move shared hooks, helpers and context out into their own file. Constants may stay with allowConstantExport, and framework exports such as loader can be listed in allowExportNames.
Fix it fast
1Find out which cause you have
Run the linter on that file and read which export it names. The cause depends on what is exported next to the component.
npx eslint src/components/Button.tsx2Match what you see, then jump to its fix
- 1
The warning points at export const useThing or export const ThemeContext in a .tsx file that also exports a componentA helper, hook or context is exported next to a componentFix - 2
The warning names an exported string, number or booleanA plain constant is exported with a componentFix - 3
The warning names loader, action, meta, links or headers in a Remix-style routeA framework requires extra exports from route filesFix - 4
The warning mentions export *, an anonymous default export or a class componentAn export shape the plugin cannot handleFix
- 1
What does the error look like?
Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.react-refresh/only-export-components
Cause 1 of 4
A helper, hook or context is exported next to a component
1Check
The plugin README says the rule enforces that components are structured the way react-refresh expects. A file that exports a function or object besides components breaks that.
grep -n "^export" src/context/ThemeContext.tsx2Fix
Move the non-component export to its own file and import it where used. The component file then exports components only.
// theme-context.ts (new file)
export const ThemeContext = createContext('light')
// ThemeProvider.tsx
import { ThemeContext } from './theme-context'
export function ThemeProvider({ children }) { /* ... */ }3Verify
Lint again, then edit the component in the browser and see state survive.
npx eslint srcConfirmed by github.com
Cause 2 of 4
A plain constant is exported with a component
1Check
The vite preset turns allowConstantExport on, the default does not. If you wrote the rule by hand, it is off.
grep -n -B2 -A4 "only-export-components" eslint.config.*2Fix
Use the vite preset, or set allowConstantExport. Per the plugin docs it stops warning when a constant (string, number, boolean, template literal) is exported beside components.
// eslint.config.js
import { defineConfig } from "eslint/config";
import { reactRefresh } from "eslint-plugin-react-refresh";
export default defineConfig(
reactRefresh.configs.vite(),
);3Verify
Run ESLint; the warning for the constant is gone.
npx eslint srcConfirmed by github.com
Cause 3 of 4
A framework requires extra exports from route files
1Check
Some frameworks handle refresh of specific exports themselves. The plugin has an option for exactly that.
grep -n "export const \(loader\|action\|meta\)" app/routes/*.tsx2Fix
List those export names in allowExportNames.
"react-refresh/only-export-components": [
"warn",
{ allowExportNames: ["meta", "links", "headers", "loader", "action"] },
]3Verify
Lint the route file again.
npx eslint app/routesConfirmed by github.com
Cause 4 of 4
An export shape the plugin cannot handle
1Check
The plugin reports export * as an error and does not support anonymous default exports or class components.
grep -n "export \*\|export default (\|export default function (" src -r2Fix
Name the component and export it by name or as a named default, and replace export * with explicit exports.
export default function Dashboard() {
return <main />
}3Verify
Lint again; the shape warning is gone.
npx eslint srcConfirmed by github.com
How do I stop it coming back?
- Keep hooks, contexts and helpers in files that export no components.
- Use the vite preset in a Vite project instead of writing the rule from scratch.
- Do not disable the rule file-wide; a disabled warning means state resets on every edit.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Editing a component reloads the page instead of hot-updating it
Component state resets on every save
Fast Refresh only works for modules whose exports are React components.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix