As per this (currently) open issue on the eslint-plugin-react-refresh project, this is most likely a false positive.

The author of the project suggests these work-arounds

There are two solutions:

  • Put a disable comment for this rule for all the file. This will not actually break fast refresh so this ok>
  • Instead of exporting the router, export a component that render the Router provider
🌐
GitHub
github.com › shadcn-ui › ui › issues › 1534
Export pattern causes warning from `eslint-plugin-react-refresh` · Issue #1534 · shadcn-ui/ui
September 16, 2023 - After initializing in a new React Vite TS Storybook starter, that happened to have this eslint plugin installed, I get warnings on a number of files that export functions in addition to a component. Also, although documentation about "Fast Refresh" is a bit scant unfortunately, some resources on it also say that each export requires its own export statement... https://github.com/ArnaudBarre/eslint-plugin-react-refresh ... { plugins: ['react-refresh'], rules: { 'react-refresh/only-export-components': [ 'warn', { allowConstantExport: true }, ], }, }
Author   lunelson
🌐
GitHub
github.com › shadcn-ui › ui › issues › 8489
[bug]: Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components. eslint(react-refresh/only-export-components · Issue #8489 · shadcn-ui/ui
October 16, 2025 - Use a new file to share constants or functions between components. eslint(react-refresh/only-export-components#8489 ... When Initialize Shadcnui import button component using Vite (version:7.1.7) +react(version:19.1.1) I'm not sure if it's ...
Author   BinLee1226
Discussions

reactjs - How to avoid ESLint warning in React: Fast refresh only works when a file only exports components? - Stack Overflow
Task: I'm trying to use React.lazy function for dynamic loading of React components. Problem: I get the following ESLint warning: ESLint: Fast refresh only works when a file only exports components. More on stackoverflow.com
🌐 stackoverflow.com
reactjs - Error: Fast refresh only works when a file only exports components - Stack Overflow
Fast refresh only works when a file only exports components. Move your component(s) to a separate file.eslint(react-refresh/only-export-components) More on stackoverflow.com
🌐 stackoverflow.com
How is this done in real life work? React Context warning "Fast refresh only works..."
If a context, hook, constant, (or anything really) is being used by two "unrelated" components, it's usually best practice to move the it to a separate file. What I would do here is // cart-context.js export const CartContext = createContext(); And then import it to those files that need it. To prevent yourself from kicking your own foot, you can export a custom hook instead for a nicer DX. // cart-context.js export const CartContext = createContext(); export const useCartContext = () => { const context = useContext(CartContext); if (!context) throw new Error("useCartContext must be used within a CartContextProvider"); return context; } More on reddit.com
🌐 r/react
13
11
April 19, 2025
Loader warning "Fast refresh only works when a file only exports components..."
Hi, I'm trying to use React Router in my React Vite app testing my page with a loader but it comes with a warning on the loader const name: "Fast refresh only works when a file only export... More on github.com
🌐 github.com
3
15
🌐
GitHub
github.com › shadcn-ui › ui › issues › 7736
[bug]: Components are exporting constants and functions causing Fast Refresh lint issue · Issue #7736 · shadcn-ui/ui
July 4, 2025 - This causes ESLint to throw the following error 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)
Author   SayakMukhopadhyay
🌐
npm
npmjs.com › package › eslint-plugin-react-refresh
eslint-plugin-react-refresh - npm
1 month ago - 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. { "react-refresh/only-export-components": [ "error", { "allowConstantExport": true } ] }
      » npm install eslint-plugin-react-refresh
    
Published   Feb 23, 2026
Version   0.5.2
Author   Arnaud Barré
🌐
DEV Community
dev.to › md_belayethossain_56e787 › fast-refresh-only-works-when-a-file-only-exports-components-why-does-this-problem-occur-and-how-1b4
Fast refresh only works when a file only exports components. Why does this problem occur? And how do we solve it? - DEV Community
May 9, 2025 - React Fast Refresh identifies React ... you make code changes. If the file contains non-component exports, Fast Refresh cannot reliably determine which parts of the code should be treated as components, leading to this ESLint ...
🌐
GitHub
github.com › shadcn-ui › ui › discussions › 5933
Is the "react-refresh/only-export-components" warning in eslint a problem? · shadcn-ui/ui · Discussion #5933
If you enable the "react-refresh/only-export-components" lint check in eslint on a React project, then it will complain about non-component exports from shadcn components. This eslint check is only...
Author   shadcn-ui
🌐
GitHub
github.com › ArnaudBarre › eslint-plugin-react-refresh
GitHub - ArnaudBarre/eslint-plugin-react-refresh: Validate that your components can safely be updated with Fast Refresh · GitHub
This plugin provides a single rule, react-refresh/only-export-components. There are multiple ways to enable it. import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig( ...
Starred by 329 users
Forked by 23 users
Languages   TypeScript 95.3% | JavaScript 4.7%
Find elsewhere
🌐
Reddit
reddit.com › r/react › how is this done in real life work? react context warning "fast refresh only works..."
r/react on Reddit: How is this done in real life work? React Context warning "Fast refresh only works..."
April 19, 2025 -

SOLVED: I ended up making a context.jsx and a provider.jsx, which seems kinda weird to me, but what do i know im just a jr.

Hello! I'm trying to learn to use contexts but i get this warning "Fast refresh only works when a file only exports components. Move your component(s) to a separate file."

I get it, its because im exporting twice. But how should i do it correctly? 2 files? One for context and one for provider??

This is my context.jsx, then i have a Cart.jsx where i plan to use it, and a Layout.jsx that wraps the outlet with the context

import {useState, createContext } from "react";

export const CartContext = createContext()

export function CartProvider({children}){
    const [cart, setCart] = useState([])

    const handleCart = (new) =>{
        setCart((prevCart) => [...prevCart, new])
    }

    return(
        <CartContext.Provider value={{cart, handleCart }}>
            {children}
        </CartContext.Provider>
    )
}
🌐
GitHub
github.com › yannickcr › eslint-plugin-react › issues › 3176
new rule: forbid exporting React Components and non-components from the same module · Issue #3176 · jsx-eslint/eslint-plugin-react
July 15, 2024 - According to the official react-fast-refresh docs: If you edit a module that only exports React component(s), Fast Refresh will update the code only for that module, and re-render your component. You can edit anything in that file, inclu...
Author   Alloyed
🌐
UNPKG
app.unpkg.com › eslint-plugin-react-refresh@0.3.4 › files › README.md
eslint-plugin-react-refresh
To reduce the number of false positive, only files importing `react` are checked. ```json { "react-refresh/only-export-components": ["warn", { "checkJS": true }] } ```
🌐
GitHub
github.com › remix-run › react-router › discussions › 10969
Fast refresh only works when a file only export components. Move your component(s) to a separate file.eslint(react-refresh/only-expor · remix-run/react-router · Discussion #10969
October 27, 2023 - Fast refresh only works when a file only export components. Move your component(s) to a separate file.eslint(react-refresh/only-expor
Author   remix-run
🌐
Biome
biomejs.dev › linter › rules › use-component-export-only-modules
useComponentExportOnlyModul... - Biome.js
> 1 │ const App = () => {} │ ^^^ 2 │ createRoot(document.getElementById(“root”)).render(<App />); 3 │ ℹ Fast Refresh only works when a file only exports components. ℹ Consider separating component exports into a new file. ℹ ...
🌐
Gatsby
gatsbyjs.com › documentation › reference guides
Fast Refresh | Gatsby
The file you’re editing might have other exports in addition to a React component. Gatsby includes an ESLint rule by default to warn against this pattern in pages: Page templates must only export one default export (the page) and query as a named export.
🌐
Reddit
reddit.com › r/nextjs › how to diagnose "fast refresh had to perform a full reload"?
r/nextjs on Reddit: How to Diagnose "Fast Refresh had to perform a full reload"?
July 7, 2023 -

I've been getting "Fast Refresh had to perform a full reload. See https://nextjs.org/docs/basic-features/fast-refresh#how-it-works" warnings in my dev logs and it'd be nice to not.

I'm going to guess the culprit is exporting the props types along with the component. However, I'm guilty of doing this a lot and refactoring would be a pain unless I know it is in fact the issue.

Is there a good way to determine the actual cause? a lint rule? a verbose log?

🌐
GitHub
github.com › shadcn-ui › ui › issues › 4288
[feat]: Better support for JavaScript using JSDocs. · Issue #4288 · shadcn-ui/ui
December 6, 2021 - Slot : "button"; return ( <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} /> ); }, ); Button.displayName = "Button"; // eslint-disable-next-line react-refresh/only-export-components export { Button, buttonVariants }; This ensures wherever i import this Button i can properly use the intellisense for variants, sizes or the rest of the button props.
Author   redoxahmii
🌐
The Candid Startup
thecandidstartup.org › 2024 › 07 › 15 › bootstrapping-eslint.html
Bootstrapping ESLint
October 27, 2023 - /* eslint-disable react-refresh/only-export-components */
🌐
npm
npmjs.com › package › @types › eslint-plugin-react-refresh
@types/eslint-plugin-react-refresh - npm
June 8, 2023 - Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/eslint-plugin-react-refresh. import { Rule } from "eslint"; export const rules: { "only-export-components": Rule.RuleModule; }; Last updated: Wed, 20 Nov 2024 21:40:28 GMT ·
      » npm install @types/eslint-plugin-react-refresh