---
title: "eslint-plugin-react-refresh: What It Does | Since.dev"
description: "eslint-plugin-react-refresh checks that React files only export components, so Fast Refresh keeps state. Its errors, fixes, 0.5 setup and the Oxlint switch."
canonical_url: https://since.dev/guides/eslint-plugin-react-refresh
last_updated: 2026-12-04
---

# What is eslint-plugin-react-refresh, and how do you fix its errors?

eslint-plugin-react-refresh is an ESLint plugin with one rule, react-refresh/only-export-components. It flags files that export a React component next to something else, like a helper, a constant or a context, because Fast Refresh can't update those files in place. The fix is almost always to move the extra export to its own file.

By [Nabil A](https://since.dev/about.md). Updated December 4, 2026

## What does eslint-plugin-react-refresh do?

It checks the shape of each file's exports so React Fast Refresh, the hot reloading in Vite, Next.js and other bundlers, can swap a component without a full page reload and without losing its state. It has exactly one rule, `react-refresh/only-export-components`, and it decides what's a component by naming: PascalCase for components, camelCase for everything else ([the plugin's README](https://github.com/ArnaudBarre/eslint-plugin-react-refresh)).

It's everywhere. The latest version is 0.5.8, published November 15, 2026, and it had 31,050,741 downloads in the week of November 27 to December 3, 2026 ([npm's download counts](https://api.npmjs.org/downloads/point/last-week/eslint-plugin-react-refresh)).

To see what it catches, I wrote four small files and ran ESLint 10.16.0 with the plugin's recommended preset. ESLint's per-file lines are long, so I cut them from the output below; every message is in the table in the next section.

- `Button.jsx` exports `formatPrice`, `MAX_ITEMS` and the `Button` component.
- `ThemeContext.jsx` exports `ThemeContext` from `createContext` and a `ThemeProvider` component.
- `Anon.jsx` has `export default function () {}` with no name.
- `index.jsx` has `export * from "./Button.jsx"`.

```
$ npm i -D eslint@10 eslint-plugin-react-refresh
$ npx eslint src
...
✖ 5 problems (5 errors, 0 warnings)
$ echo $?
1
```

All four files failed, Button.jsx twice. The exact messages are in the next section, with the fix for each. Note what it doesn't do: it never touches production builds, because Fast Refresh only runs in development. A file the rule flags still works; you just get a slower, state-losing reload when you edit it.

## How do I fix "Fast refresh only works when a file only exports components"?

Move the non-component export to its own file and import it where you need it. That one move fixes the most common message. The rule prints four different messages, and each has its own fix:

The messages eslint-plugin-react-refresh 0.5.8 printed on Dec 4, 2026, and the fix for each

| Message                                                                                                                        | What triggers it                                                                     | Fix                                                                                                                |
| ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components | A component exported next to a function or a constant, like formatPrice or MAX_ITEMS | Move the helper to format.js and import it. For plain constants, the allowConstantExport option also works on Vite |
| Fast refresh only works when a file only exports components. Move your React context(s) to a separate file                     | A createContext() result exported next to its provider                               | Put createContext() in ThemeContext.js and keep only the provider component in the .jsx file                       |
| Fast refresh can't handle anonymous components. Add a name to your export                                                      | export default function () {} or an anonymous arrow                                  | export default function Anon() {}                                                                                  |
| This rule can't verify that \`export \*\` only exports components                                                              | export \* from "./Button.jsx" in a barrel file                                       | Name the exports: export { Button } from "./Button.jsx"                                                            |

Two more cases the README lists: exporting an array of JSX elements (`export const tabs = [<Tab />]`) and calling `createRoot(...).render(<App />)` in the same file that defines `App`. Keep the render call in `main.jsx` and import the component ([README examples](https://github.com/ArnaudBarre/eslint-plugin-react-refresh)).

If you wrap components in your own higher-order component, like `observer(Button)` or `connect(...)(Button)`, list it in `extraHOCs` so the rule knows the result is a component. Since 0.5.0 the rule no longer knows `connect` from react-redux on its own ([changelog](https://github.com/ArnaudBarre/eslint-plugin-react-refresh/blob/main/CHANGELOG.md)).

## Why does Fast Refresh need files that only export components?

Because Fast Refresh can only swap a module in place when every export is a component it can re-render. Any other export might be read by code outside React, so the bundler gives up on the in-place update and reloads the importers instead. Vite's React plugin says it plainly: "your file should only export React components" ([plugin-react README](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#consistent-components-exports)).

Here's what that looks like. I created a fresh Vite 8.4.1 app, added a `Price.jsx` that exported both `formatPrice` and a `Price` component, opened the page in a browser and edited the file. Vite's dev server logged `hmr invalidate /src/Price.jsx Could not Fast Refresh ("formatPrice" export is incompatible)`, then an update of `/src/App.jsx`, the importer. That's the state-losing path. After I moved `formatPrice` to `format.js`, the next edit logged only `hmr update /src/Price.jsx`: the component updated in place.

Next.js gives the same reason in its own docs: local state resets on every edit when "the file you're editing might have other exports in addition to a React component", and anonymous arrow default exports don't keep state either ([Next.js Fast Refresh](https://nextjs.org/docs/architecture/fast-refresh)). So the rule isn't a Vite quirk. It's how React Fast Refresh works everywhere.

## How do I set up eslint-plugin-react-refresh with ESLint 9 or 10?

Install it, then add one of its three presets to a flat config. Since 0.5.0 the package is ESM only and needs ESLint 9 or 10 and Node.js 20, and its peer range is `^9 || ^10` ([changelog](https://github.com/ArnaudBarre/eslint-plugin-react-refresh/blob/main/CHANGELOG.md); npm registry, read Dec 4, 2026). The old `.eslintrc` format can't load it.

1. Install it: `npm i -D eslint-plugin-react-refresh`.
2. Import the named export `reactRefresh` in `eslint.config.js`.
3. Call the preset that matches your setup: `recommended()` for plain React, `vite()` for Vite (it turns on `allowConstantExport` and `allowCompoundComponents`), or `next()` for Next.js (it allows exports like `revalidate` and `fetchCache`).
4. Run ESLint and fix what it reports, using the table above.

```
import { defineConfig } from "eslint/config"
import { reactRefresh } from "eslint-plugin-react-refresh"

export default defineConfig({
  files: ["**/*.{jsx,tsx}"],
  extends: [reactRefresh.configs.vite()],
})
```

With `vite()` instead of `recommended()`, the same four files gave 4 errors instead of 5: `MAX_ITEMS = 10` was allowed, because Vite only invalidates the module when a constant's value changes. The function `formatPrice` was still reported.

### The two config mistakes, and the errors they print

The package has two exports, and they work differently. The default export's `configs.vite` is a plain config object; the named export's `reactRefresh.configs.vite` is a function you call. Mix them up and ESLint 10.16.0 stops before linting anything:

What ESLint 10.16.0 printed for each mix-up on Dec 4, 2026

| Config line                                               | Error                                                  | Fix                                                        |
| --------------------------------------------------------- | ------------------------------------------------------ | ---------------------------------------------------------- |
| Default import, then reactRefresh.configs.vite()          | TypeError: reactRefresh.configs.vite is not a function | Drop the parentheses, or switch to import { reactRefresh } |
| Named import, then reactRefresh.configs.vite with no call | TypeError: Unexpected function.                        | Add the parentheses: configs.vite()                        |

Vite's own generated config uses the first style (default import, no call), so copying from an older tutorial into a config that uses the named import is the usual way to hit the second error.

## Why is eslint-plugin-react-refresh not reporting anything?

Most often because your components live in .js files. By default the rule only checks .jsx and .tsx files, to avoid false positives ([README](https://github.com/ArnaudBarre/eslint-plugin-react-refresh)). I copied `Button.jsx` to `Button.js` and ran the same config: no errors, exit 0.

Turning on `checkJS: true` didn't change that at first. The option only checks .js files that import `react`. Once I added `import { useState } from "react"` to the top, the same file gave 2 errors. If your .js components never import React (the new JSX transform doesn't need it), rename them to .jsx.

The other causes I'd check, in order:

- Your config block's `files` pattern doesn't match the files, or the preset sits in a block for other files.
- You're on `.eslintrc`. ESLint 10 dropped it and the 0.5 plugin can't load there; move to flat config ([ESLint's migration guide](https://eslint.org/docs/latest/use/configure/migration-guide)).
- Your project now lints with Oxlint, not ESLint, which is what a new Vite app does (next section).
- The component isn't PascalCase, so the rule treats it as a plain function, or the file uses class components, which the rule doesn't support.

## Does Vite still use eslint-plugin-react-refresh?

Not by default. Since create-vite 9.1.0 (June 23, 2026), the React templates lint with Oxlint, and ESLint with this plugin is an option behind `--eslint` ([create-vite changelog](https://github.com/vitejs/vite/blob/main/packages/create-vite/CHANGELOG.md), PR #22638). The template I scaffolded today with create-vite 9.4.0 ships `oxlint ^1.94.0` and this `.oxlintrc.json`:

```
{
  "plugins": ["react", "oxc"],
  "rules": {
    "react/rules-of-hooks": "error",
    "react/only-export-components": [
      "warn",
      { "allowConstantExport": true }
    ]
  }
}
```

That's the same rule, ported. If you want ESLint instead, ask for it when you create the app:

```
$ npm create vite@latest app -- \
    --template react-ts --eslint
```

That writes an `eslint.config.js` with `reactRefresh.configs.vite`, adds `eslint ^10.15.0` and `eslint-plugin-react-refresh ^0.5.8`, and pins `typescript` to `~6.0.3` instead of the template's `~7.0.2`. The changelog calls that fix "keep TypeScript 6 when using ESLint": typescript-eslint 8.74.0, the latest on Dec 4, 2026, accepts TypeScript from 4.8.4 up to, but not including, 6.1.0 (npm registry). If you add ESLint to a Vite app by hand later, keep that pin. The [ESLint React comparison](https://since.dev/guides/eslint-plugin-react-vs-eslint-react.md) shows the crash you get without it.

## What's the Oxlint or Biome equivalent of react-refresh/only-export-components?

Oxlint has `react/only-export-components`, a port of this rule ([Oxlint docs](https://oxc.rs/docs/guide/usage/linter/rules/react/only-export-components), added in v1.23.0). Biome has `style/useComponentExportOnlyModules`, "inspired from" it, since v1.9.2, not on by default ([Biome docs](https://biomejs.dev/linter/rules/use-component-export-only-modules/)). I ran both on the same four files. Oxlint matched the ESLint plugin; Biome missed two cases.

Same four files on Dec 4, 2026: eslint-plugin-react-refresh 0.5.8 flagged all five cases

| Case                                  | Oxlint 1.96.0                                     | Biome 2.6.10                                  |
| ------------------------------------- | ------------------------------------------------- | --------------------------------------------- |
| Function exported next to a component | Flagged                                           | Flagged                                       |
| Constant exported next to a component | Flagged                                           | Flagged                                       |
| Context exported next to its provider | Flagged, with the context message                 | Flagged, with the general message             |
| Anonymous default export              | Flagged                                           | Not flagged                                   |
| export \*                             | Flagged                                           | Not flagged                                   |
| Options                               | Five, but the HOC list is still called customHOCs | allowConstantExport and allowExportNames only |

Watch the option name when you move a config across. The ESLint plugin renamed `customHOCs` to `extraHOCs` in 0.5.0, and Oxlint's docs still list `customHOCs`. Oxlint's messages are word for word the ESLint plugin's, so the fixes table above applies to it too.

Which should you use? If you already run ESLint for other plugins, keep this one. If you lint with Oxlint, its rule is a drop-in. I'd only lean on Biome's rule if Biome is already your linter, and I'd add a quick review of barrel files, since it didn't catch `export *`. For the bigger ESLint plugin question, see [eslint-plugin-react vs ESLint React](https://since.dev/guides/eslint-plugin-react-vs-eslint-react.md).

## What changed in eslint-plugin-react-refresh 0.5?

0.5.0 (February 1, 2026) was a breaking release even though the version still starts with 0, and a caret range like `^0.4.20` won't pull it in. What changed, from the [changelog](https://github.com/ArnaudBarre/eslint-plugin-react-refresh/blob/main/CHANGELOG.md):

- The package ships as ESM and needs ESLint 9 and Node.js 20, so it only works in flat config.
- A named `reactRefresh` export with `plugin` and preset functions is now preferred over the default export.
- `customHOCs` was renamed to `extraHOCs`.
- HOC calls are checked more strictly, and `connect` from react-redux is no longer recognized unless you list it in `extraHOCs`.

After that: 0.5.1 (February 23) marked ESLint 10 as supported, 0.5.7 (September 14) added `allowCompoundComponents` for objects like `export const Tag = { Root, Label }`, and 0.5.8 (November 15) handles more `export default` cases. Bing's answer for this query still called 0.5.3 the latest on December 4, 2026; it's 0.5.8. To see every change between the version you're on and the latest, [compare the two versions](https://since.dev/guides/breaking-changes-between-versions.md) before you bump.

## Where Since.dev fits

Since.dev answers the upgrade half of this question. When I asked it what changed in eslint-plugin-react-refresh since 0.4.26, it said the project was nine releases behind and listed each change with its source: the flat config requirement, Node.js 20, the `customHOCs` rename, the `connect` removal and the new options. A coding agent gets the same answer from `whats_changed` before it touches your lint setup. It also has pages for the linters themselves, like [ESLint's breaking changes](https://since.dev/packages/npm/eslint) and [Oxlint's](https://since.dev/packages/npm/oxlint). It won't fix your exports for you; that's still your call. It reports what changed or opens a pull request for review, and nothing merges or deploys without you.

## Pages on Since.dev

- [eslint-plugin-react-refresh breaking changes by version](https://since.dev/packages/npm/eslint-plugin-react-refresh.md)

## Questions

### Does eslint-plugin-react-refresh support ESLint 10?

Yes. Version 0.5.1, published February 23, 2026, marked ESLint 10 as supported, and the current 0.5.8 declares a peer range of ^9 || ^10. It does not support ESLint 8 or the old .eslintrc format, because since 0.5.0 it ships as ESM only.

### Should react-refresh/only-export-components be a warning or an error?

Either works, because the rule only protects the development experience and never breaks a production build. Vite's Oxlint template sets it to warn, while the plugin's own presets set it to error. I'd use error if lint runs in CI, since the fix is usually moving one export to another file.

### Is eslint-plugin-react-refresh the same as eslint-plugin-react-hooks?

No. eslint-plugin-react-hooks checks how you call hooks, such as the rules of hooks and effect dependencies. eslint-plugin-react-refresh only checks what a file exports, so Fast Refresh can update it in place. Vite's ESLint setup uses both side by side.

### Do I need eslint-plugin-react-refresh with Next.js?

It's optional, but it catches the same problem Next.js documents: a file that exports something besides a component resets its state on every edit. If you use it, pick the next() preset, which allows Next.js exports such as revalidate and fetchCache.

### Why does Vite say "Could not Fast Refresh" when I edit a file?

The file exports something Fast Refresh can't treat as a component, so Vite invalidates it and reloads the files that import it instead of updating in place. The log names the export, for example "formatPrice" export is incompatible. Move that export to its own file and the next edit updates in place.

## Related guides

### Comparisons

- [eslint-plugin-react vs @eslint-react/eslint-plugin: which should you use?](https://since.dev/guides/eslint-plugin-react-vs-eslint-react.md): eslint-plugin-react vs @eslint-react/eslint-plugin, run on ESLint 9 and 10: which installs, which crashes, rules, TypeScript 7 and how to migrate.
- [eslint-plugin-import vs eslint-plugin-import-x: which should you use?](https://since.dev/guides/eslint-plugin-import-vs-import-x.md): eslint-plugin-import vs eslint-plugin-import-x, run on ESLint 10: which installs, which crashes, package exports, rules, dependencies and how to switch.

### How-to

- [How to find the breaking changes between two versions of a package](https://since.dev/guides/breaking-changes-between-versions.md): How to find breaking changes between two versions of a package: list the releases in between, read each changelog, diff the code. Commands for npm, PyPI, Go.
- [How to check your dependencies for breaking changes before you upgrade](https://since.dev/guides/dependency-breaking-changes.md): How to check dependencies for breaking changes before upgrading: the commands, a real failing upgrade, CI that fails on deprecations, and where notices appear.

### Explainers

- [Caret vs tilde in package.json: what ^ and \~ let in](https://since.dev/guides/caret-vs-tilde-package-json.md): Caret (^) allows minor and patch updates, tilde (\~) only patches. The 0.x exception, what your lockfile does, and how ^ and \~ differ in Cargo and Composer.

## Put your code on continuous maintenance.

Scan a public repository now, or give your agent one line.

[Scan a repository](https://since.dev/scan.md). Any public GitHub repository. No sign-in.

### Tell your agent what changed since it was trained.

`claude mcp add --transport http since https://api.since.dev/mcp`

[Get an API key](https://app.since.dev/login?mode=signup)

Codex, Cursor and any MCP client use https://api.since.dev/mcp.

---

Every page on this site as Markdown: https://since.dev/sitemap.md. For agents: https://since.dev/llms.txt.
