### Install eslint-plugin-react-refresh Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Install the plugin as a dev dependency using npm. ```sh npm i -D eslint-plugin-react-refresh ``` -------------------------------- ### Basic recommended preset usage Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Configures ESLint using the recommended preset from the reactRefresh plugin. This is the basic setup for React Refresh support. ```js import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig( reactRefresh.configs.recommended(), ); ``` -------------------------------- ### allowCompoundComponents allowed code Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Example of code that becomes allowed when allowCompoundComponents is enabled. ```jsx const Root = () => <>; const Label = () => <>; export const Tag = { Root, Label }; ``` -------------------------------- ### Next preset usage Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Configures ESLint using the Next preset from the reactRefresh plugin. This is the setup for Next.js projects. ```js import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig( reactRefresh.configs.next(), ); ``` -------------------------------- ### Pass: Valid component exports Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md These examples are allowed by the rule because they export only components or use proper patterns. ```jsx export default function Foo() { return <>; } ``` ```jsx const foo = () => {}; export const Bar = () => <>; ``` ```jsx import { App } from "./App"; createRoot(document.getElementById("root")).render(); ``` -------------------------------- ### allowConstantExport allowed code Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Example of code that becomes allowed when allowConstantExport is enabled. ```jsx export const CONSTANT = 3; export const Foo = () => <>; ``` -------------------------------- ### Fail: Exporting non-component values Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md These examples trigger the rule because they export non-component values or use patterns that break fast refresh. ```jsx export const foo = () => {}; export const Bar = () => <>; ``` ```jsx export default function () {} export default compose()(MainComponent) ``` ```jsx export * from "./foo"; ``` ```jsx const Tab = () => {}; export const tabs = [, ]; ``` ```jsx const App = () => {}; createRoot(document.getElementById("root")).render(); ``` -------------------------------- ### Destructure rule options with defaults Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/only-export-components.md Extracts rule options from `context.options[0]` with defaults for `extraHOCs`, `allowExportNames`, `allowConstantExport`, `allowCompoundComponents`, and `checkJS`. Used at the start of the `create` function. ```typescript const { extraHOCs = [], allowExportNames, allowConstantExport = false, allowCompoundComponents = false, checkJS = false, } = context.options[0] ?? {}; ``` -------------------------------- ### Suppress react-refresh/only-export-components on a single line or file Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/errors.md Use eslint-disable comments to suppress the rule for a single line or a block of code. The first example disables the rule for the next line, the second disables it for a block and re-enables it after. ```jsx // eslint-disable-next-line react-refresh/only-export-components export const tabs = [, ]; ``` ```jsx /* eslint-disable react-refresh/only-export-components */ export const meta = { title: "Home" }; export const loader = async () => ({}); /* eslint-enable react-refresh/only-export-components */ ``` -------------------------------- ### reactRefresh.configs.recommended(options?) Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Creates an ESLint flat config object for the 'recommended' preset. Accepts optional rule options that override the preset defaults (which are empty). ```APIDOC ## reactRefresh.configs.recommended(options?) ### Description Creates an ESLint flat config object for the 'recommended' preset. Accepts optional rule options that override the preset defaults (which are empty). ### Method Function call ### Endpoint reactRefresh.configs.recommended ### Parameters #### Function Parameters - **options** (OnlyExportComponentsOptions) - Optional - Rule options merged over the preset's baseOptions via shallow spread. Individual fields override preset defaults; omitted fields keep preset values. ### Return Value An ESLint flat config object of type Config with: - **name**: "react-refresh/recommended" - **plugins**: { "react-refresh": plugin } - **rules**: { "react-refresh/only-export-components": ["error", mergedOptions] } ### Example ```js const config = reactRefresh.configs.recommended(); ``` ``` -------------------------------- ### allowCompoundComponents option configuration Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Configure allowCompoundComponents to avoid warnings when exporting components as an object. ```json { "react-refresh/only-export-components": [ "error", { "allowCompoundComponents": true } ] } ``` -------------------------------- ### Basic usage in flat config Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/only-export-components.md Configures the rule with recommended settings and optionally re-configures with custom options like extraHOCs and allowConstantExport. ```javascript import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig( reactRefresh.configs.recommended(), // Optionally re-configure with your own options { rules: { "react-refresh/only-export-components": [ "error", { extraHOCs: ["withAuth"], allowConstantExport: true }, ], }, }, ); ``` -------------------------------- ### Manual plugin wiring without presets Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Wires the plugin manually without using presets, allowing full control over the configuration. Includes the only-export-components rule with allowConstantExport option. ```js import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig({ plugins: { "react-refresh": reactRefresh.plugin, }, rules: { "react-refresh/only-export-components": [ "error", { allowConstantExport: true }, ], }, }); ``` -------------------------------- ### buildConfig helper implementation Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Internal helper that creates config factory functions. It takes a name and base options, and returns a function that merges user options over the base options via shallow spread. ```TypeScript const buildConfig = ({ name, baseOptions, }: { name: string; baseOptions: OnlyExportComponentsOptions; }) => (options?: OnlyExportComponentsOptions) => ({ name: `react-refresh/${name}`, plugins: { "react-refresh": plugin }, rules: { "react-refresh/only-export-components": [ "error", { ...baseOptions, ...options }, ], }, }); ``` -------------------------------- ### reactRefresh.configs.next(options?) Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Creates an ESLint flat config object for the 'next' preset. Accepts optional rule options that override the preset defaults (allowExportNames list for Next.js App Router exports). ```APIDOC ## reactRefresh.configs.next(options?) ### Description Creates an ESLint flat config object for the 'next' preset. Accepts optional rule options that override the preset defaults (allowExportNames list for Next.js App Router exports). ### Method Function call ### Endpoint reactRefresh.configs.next ### Parameters #### Function Parameters - **options** (OnlyExportComponentsOptions) - Optional - Rule options merged over the preset's baseOptions via shallow spread. Individual fields override preset defaults; omitted fields keep preset values. ### Return Value An ESLint flat config object of type Config with: - **name**: "react-refresh/next" - **plugins**: { "react-refresh": plugin } - **rules**: { "react-refresh/only-export-components": ["error", mergedOptions] } ### Example ```js const config = reactRefresh.configs.next(); ``` ``` -------------------------------- ### Recommended config for eslint-plugin-react-refresh Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Use the recommended config to enable the react-refresh/only-export-components rule with default options. ```js import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig( /* Main config */ reactRefresh.configs.recommended(), ); ``` -------------------------------- ### checkJS option configuration Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Configure checkJS to enable the rule for .js files containing JSX. ```json { "react-refresh/only-export-components": ["error", { "checkJS": true }] } ``` -------------------------------- ### reactRefresh.configs.vite(options?) Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Creates an ESLint flat config object for the 'vite' preset. Accepts optional rule options that override the preset defaults (allowConstantExport: true, allowCompoundComponents: true). ```APIDOC ## reactRefresh.configs.vite(options?) ### Description Creates an ESLint flat config object for the 'vite' preset. Accepts optional rule options that override the preset defaults (allowConstantExport: true, allowCompoundComponents: true). ### Method Function call ### Endpoint reactRefresh.configs.vite ### Parameters #### Function Parameters - **options** (OnlyExportComponentsOptions) - Optional - Rule options merged over the preset's baseOptions via shallow spread. Individual fields override preset defaults; omitted fields keep preset values. ### Return Value An ESLint flat config object of type Config with: - **name**: "react-refresh/vite" - **plugins**: { "react-refresh": plugin } - **rules**: { "react-refresh/only-export-components": ["error", mergedOptions] } ### Example ```js const config = reactRefresh.configs.vite(); ``` ``` -------------------------------- ### Using the rule standalone with a custom severity Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/only-export-components.md Configures the rule standalone with a custom severity (warn) and options like checkJS and allowExportNames. ```javascript import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig({ files: ["**/*.{ts,tsx}"], plugins: { "react-refresh": reactRefresh.plugin }, rules: { "react-refresh/only-export-components": [ "warn", { checkJS: true, allowExportNames: ["loader", "action"] }, ], }, }); ``` -------------------------------- ### Manual config for eslint-plugin-react-refresh Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Manually configure the plugin and rule without using a preset config. ```js import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig({ // in main config for TSX/JSX source files plugins: { "react-refresh": reactRefresh.plugin, }, rules: { "react-refresh/only-export-components": "error", }, }); ``` -------------------------------- ### package.json exports map Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md The exports map for the package, specifying the types and default entry points. ```json { "exports": { ".": { "types": "./index.d.ts", "default": "./index.js" } } } ``` -------------------------------- ### Legacy default export usage Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Uses the legacy default export of the plugin, which is still supported. This approach uses the plugin object directly and applies the recommended rules. ```js import plugin from "eslint-plugin-react-refresh"; export default [ { plugins: { "react-refresh": plugin }, rules: plugin.configs.recommended.rules, }, ]; ``` -------------------------------- ### Default export Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md The default export exposes the plugin's rules and configuration objects for the recommended, vite, and next presets. ```APIDOC ## Default export ### Description Exports the plugin's rules and configuration objects for the recommended, vite, and next presets. ### Type ```ts declare const defaultExport: { rules: Rules; configs: { recommended: Config; vite: Config; next: Config; }; }; export default defaultExport; ``` ### Properties - **rules** (Rules) - The plugin's rules. - **configs.recommended** (Config) - Configuration object for the recommended preset. - **configs.vite** (Config) - Configuration object for the Vite preset. - **configs.next** (Config) - Configuration object for the Next.js preset. ``` -------------------------------- ### allowExportNames option configuration Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Configure allowExportNames to avoid warnings for specific exports handled by frameworks like Remix. ```json { "react-refresh/only-export-components": [ "error", { "allowExportNames": ["meta", "links", "headers", "loader", "action"] } ] } ``` -------------------------------- ### Config Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md The `Config` type represents the resolved flat-config object returned by the pre-invoked default-export configs. It includes the plugin registration and rules. ```APIDOC ## Type: Config ### Description The `Config` type is the resolved flat-config object returned by the pre-invoked default-export configs. It contains the config name, the plugin registration, and the rules. ### Definition ```ts type Config = { name: string; plugins: { "react-refresh": { rules: Rules } }; rules: Rules; }; ``` ### Fields - **name** (`string`) - The config name: `"react-refresh/recommended"`, `"react-refresh/vite"`, or `"react-refresh/next"`. - **plugins** (`{ "react-refresh": { rules: Rules } }`) - The plugin registered under the `react-refresh` namespace. - **rules** (`Rules`) - The rules configuration, typed loosely as `any`. ### Notes - Does not satisfy ESLint's `FlatConfig` type as-is. Consumers should pass the object inside `defineConfig(...)` from `eslint/config`. ``` -------------------------------- ### allowConstantExport option configuration Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Configure allowConstantExport to avoid warnings when exporting constants alongside components. ```json { "react-refresh/only-export-components": [ "error", { "allowConstantExport": true } ] } ``` -------------------------------- ### Error handling (config validation) Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/only-export-components.md Illustrates that a misspelled or unsupported option key fails ESLint's config validation because additionalProperties is false. The rule never throws at lint time. ```javascript // ESLint throws: "should NOT have additional properties" // react-refresh/only-export-components: ["error", { allowConstant: true }] ``` -------------------------------- ### extraHOCs option configuration Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Configure extraHOCs to avoid false positives when exporting components wrapped in non-built-in HOCs. ```json { "react-refresh/only-export-components": [ "error", { "extraHOCs": ["observer", "withAuth"] } ] } ``` -------------------------------- ### Default export with invoked configs Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md The default export, which provides already-invoked config objects for backward compatibility. ```typescript /** Prefer reactRefresh export which exposed configs as functions */ export default { rules, configs: { recommended: configs.recommended(), vite: configs.vite(), next: configs.next(), }, }; ``` -------------------------------- ### Next config for eslint-plugin-react-refresh Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Use the Next config to allow exports like fetchCache and revalidate used in Page or Layout components. ```js import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig( /* Main config */ reactRefresh.configs.next(), ); ``` -------------------------------- ### ConfigFn Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md The `ConfigFn` type is the type of each `reactRefresh.configs.*` factory. It accepts optional options and returns a resolved `Config` object. ```APIDOC ## Type: ConfigFn ### Description The `ConfigFn` type represents the factory functions in `reactRefresh.configs.*`. It takes optional options and returns a resolved `Config` object. ### Definition ```ts type ConfigFn = (options?: OnlyExportComponentsOptions) => { name: string; plugins: { "react-refresh": { rules: Rules } }; rules: Rules; }; ``` ### Parameters - **options** (`OnlyExportComponentsOptions`) - Optional. Merged over the preset's base options with `{ ...baseOptions, ...options }`. ### Return Type Returns a resolved `Config` object (same shape as `Config`). ``` -------------------------------- ### Downgrade to warning or disable globally in eslint.config.js Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/errors.md In the flat config, import the reactRefresh plugin and use its recommended config. Set the rule to 'off' to disable globally, or use 'warn' to downgrade to a warning. ```javascript // eslint.config.js import { reactRefresh } from "eslint-plugin-react-refresh"; export default [ reactRefresh.configs.recommended(), { rules: { "react-refresh/only-export-components": "off", // globally disable }, }, ]; ``` -------------------------------- ### Options interface and defaults Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md TypeScript interface for the rule options and the default values used when options are not provided. ```ts interface Options { extraHOCs?: string[]; allowExportNames?: string[]; allowConstantExport?: boolean; allowCompoundComponents?: boolean; checkJS?: boolean; } const defaultOptions: Options = { extraHOCs: [], allowExportNames: [], allowConstantExport: false, allowCompoundComponents: false, checkJS: false, }; ``` -------------------------------- ### Vite preset with custom options Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Configures ESLint using the Vite preset with custom options merged on top, such as extraHOCs. This allows customizing the preset behavior. ```js import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig( reactRefresh.configs.vite({ extraHOCs: ["observer"] }), ); ``` -------------------------------- ### Default export Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md The default export provides the plugin rules and pre-invoked configuration objects for backward compatibility. Prefer the named export `reactRefresh` for new code. ```APIDOC ## Default Export ### Description Exports an object with the plugin rules and pre-invoked configuration objects. Kept for backward compatibility; prefer the named export `reactRefresh`. ### Signature ```ts export default { rules, configs: { recommended: configs.recommended(), vite: configs.vite(), next: configs.next(), }, }; ``` ### Properties - **rules** (`Rules`) - `{ "only-export-components": onlyExportComponents }` - **configs.recommended** (`Config`) - The resolved recommended config (severity `"error"`). - **configs.vite** (`Config`) - The resolved Vite config (severity `"error"`). - **configs.next** (`Config`) - The resolved Next.js config (severity `"error"`). ### Usage Example ```js import plugin from 'eslint-plugin-react-refresh'; export default [ { plugins: { 'react-refresh': plugin }, rules: plugin.rules, }, plugin.configs.recommended, ]; ``` ``` -------------------------------- ### meta object for only-export-components Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/only-export-components.md Declared at src/only-export-components.ts:16-47. Contains six message templates, type: "problem", and a schema with five option properties. additionalProperties: false means unknown option keys are rejected by ESLint's schema validation. ```typescript meta: { messages: { exportAll: "This rule can't verify that `export *` only exports components.", namedExport: "Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.", anonymousExport: "Fast refresh can't handle anonymous components. Add a name to your export.", localComponents: "Fast refresh only works when a file only exports components. Move your component(s) to a separate file. If all exports are HOCs, add them to the `extraHOCs` option.", noExport: "Fast refresh only works when a file has exports. Move your component(s) to a separate file.", reactContext: "Fast refresh only works when a file only exports components. Move your React context(s) to a separate file.", }, type: "problem", schema: [ { type: "object", properties: { extraHOCs: { type: "array", items: { type: "string" } }, allowExportNames: { type: "array", items: { type: "string" } }, allowConstantExport: { type: "boolean" }, allowCompoundComponents: { type: "boolean" }, checkJS: { type: "boolean" }, }, additionalProperties: false, }, ], }, ``` -------------------------------- ### ConfigFn type definition Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md Defines the type of each reactRefresh.configs.* factory. Accepts optional OnlyExportComponentsOptions and returns a resolved Config. ```typescript type ConfigFn = (options?: OnlyExportComponentsOptions) => { name: string; plugins: { "react-refresh": { rules: Rules } }; rules: Rules; }; ``` -------------------------------- ### Opting out for a single line Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/only-export-components.md Shows how to disable the rule for a single line using an eslint-disable-next-line comment, allowing a deliberate utility export. ```jsx const tabs = [, ]; // eslint-disable-next-line react-refresh/only-export-components -- deliberate util export export const getTabs = () => tabs; ``` -------------------------------- ### reactRefresh constant Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md The reactRefresh constant exposes the plugin's rules and configuration functions for the recommended, vite, and next presets. ```APIDOC ## `reactRefresh` const ### Description Exports the plugin's rules and configuration functions for the recommended, vite, and next presets. ### Type ```ts export const reactRefresh: { plugin: { rules: Rules; }; configs: { recommended: ConfigFn; vite: ConfigFn; next: ConfigFn; }; }; ``` ### Properties - **plugin.rules** (Rules) - The plugin's rules. - **configs.recommended** (ConfigFn) - Configuration function for the recommended preset. - **configs.vite** (ConfigFn) - Configuration function for the Vite preset. - **configs.next** (ConfigFn) - Configuration function for the Next.js preset. ``` -------------------------------- ### Plugin object definition Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Defines the plugin object that exposes the rules. The plugin object is the main export used in ESLint configuration. ```ts const plugin = { rules }; ``` -------------------------------- ### Vite config for eslint-plugin-react-refresh Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/README.md Use the Vite config to enable allowConstantExport and allowCompoundComponents options supported by Vite React plugins. ```js import { defineConfig } from "eslint/config"; import { reactRefresh } from "eslint-plugin-react-refresh"; export default defineConfig( /* Main config */ reactRefresh.configs.vite(), ); ``` -------------------------------- ### Config type definition Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md Defines the resolved flat-config object returned by pre-invoked default-export configs. Does not satisfy ESLint's FlatConfig type as-is; consumers should use defineConfig from eslint/config. ```typescript type Config = { name: string; plugins: { "react-refresh": { rules: Rules } }; rules: Rules; }; ``` -------------------------------- ### Rules Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md The `Rules` type is a permissive type used for the rule module. It is used in `plugin.rules`, `Config.rules`, and the default export's `rules`. ```APIDOC ## Type: Rules ### Description The `Rules` type is a permissive type that maps the rule name to `any`. It is used in the plugin's `rules` property and in the `Config` type. ### Definition ```ts type Rules = { "only-export-components": any }; ``` ### Usage - Used in `plugin.rules` - Used in `Config.rules` - Used in the default export's `rules` ``` -------------------------------- ### Default export type definition (src/types.d.ts:33-41) Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md Declares the default export object with `rules` and `configs` properties, where configs are of type `Config` (not `ConfigFn`). This is the main export of the plugin. ```TypeScript declare const defaultExport: { rules: Rules; configs: { recommended: Config; vite: Config; next: Config; }; }; export default defaultExport; ``` -------------------------------- ### Named export: reactRefresh Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md The named export `reactRefresh` is an object containing the ESLint plugin and configuration factory functions. Use it to access the plugin and build custom configs. ```APIDOC ## Named Export: `reactRefresh` ### Description Exports an object with the ESLint plugin and configuration factory functions for Fast Refresh validation. ### Signature ```ts export const reactRefresh: { plugin: { rules: Rules; }; configs: { recommended: ConfigFn; vite: ConfigFn; next: ConfigFn; }; }; ``` ### Properties - **plugin** (`{ rules: Rules }`) - The ESLint plugin object. Pass it to the `plugins` key of a flat config as `"react-refresh": reactRefresh.plugin`. - **configs.recommended** (`ConfigFn`) - Config factory with empty base options. - **configs.vite** (`ConfigFn`) - Config factory pre-enabling `allowConstantExport: true` and `allowCompoundComponents: true`. - **configs.next** (`ConfigFn`) - Config factory pre-enabling a fixed `allowExportNames` list of Next.js route-segment/metadata export names. ### Usage Example ```js import { reactRefresh } from 'eslint-plugin-react-refresh'; export default [ { plugins: { 'react-refresh': reactRefresh.plugin }, rules: { 'react-refresh/only-export-components': 'error' }, }, reactRefresh.configs.recommended(), ]; ``` ``` -------------------------------- ### Rules object definition Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md Defines the rules object containing the only-export-components rule. This rule is the only rule exposed by the plugin. ```ts const rules = { "only-export-components": onlyExportComponents, }; ``` -------------------------------- ### Return type object literal for reactRefresh Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/index.md The object literal returned by the `reactRefresh` export, containing the plugin and configs. ```typescript export const reactRefresh = { plugin, configs }; ``` -------------------------------- ### OnlyExportComponentsOptions type definition Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md Exact definition of the exported OnlyExportComponentsOptions type from src/types.d.ts:3-9. All fields are optional. Runtime defaults are documented in the table: extraHOCs defaults to [], allowExportNames defaults to undefined (no names allowed), allowConstantExport defaults to false, allowCompoundComponents defaults to false, checkJS defaults to false. ```TypeScript export type OnlyExportComponentsOptions = { extraHOCs?: string[]; allowExportNames?: string[]; allowConstantExport?: boolean; allowCompoundComponents?: boolean; checkJS?: boolean; }; ``` -------------------------------- ### Rules type definition Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md Defines the Rules type as a permissive mapping for the 'only-export-components' rule. Used in plugin.rules, Config.rules, and the default export's rules. ```typescript type Rules = { "only-export-components": any }; ``` -------------------------------- ### Next preset allowExportNames array Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/configuration.md The allowExportNames array used by the next preset to exempt Next.js App Router HMR-supported exports. This list is defined in src/index.ts:36-64. ```TypeScript allowExportNames: [ "experimental_ppr", "dynamic", "dynamicParams", "revalidate", "fetchCache", "runtime", "preferredRegion", "maxDuration", "metadata", "generateMetadata", "viewport", "generateViewport", "generateImageMetadata", "generateSitemaps", "generateStaticParams", "instant", "contentType", "size", ] ``` -------------------------------- ### reactRefresh constant type definition (src/types.d.ts:22-31) Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/types.md Defines the `reactRefresh` constant with a `plugin` property containing `rules` and a `configs` property with `recommended`, `vite`, and `next` config functions. This type is used to describe the plugin's exported API. ```TypeScript export const reactRefresh: { plugin: { rules: Rules; }; configs: { recommended: ConfigFn; vite: ConfigFn; next: ConfigFn; }; }; ``` -------------------------------- ### Type signature of onlyExportComponents Source: https://github.com/arnaudbarre/eslint-plugin-react-refresh/blob/main/_autodocs/api-reference/only-export-components.md Exact declaration from src/only-export-components.ts:7-12. The two generic parameters of TSESLint.RuleModule are MessageIds (a closed set of reportable message identifiers) and Options (no options or a single OnlyExportComponentsOptions object). ```typescript export const onlyExportComponents: TSESLint.RuleModule< | "exportAll" | "namedExport" | "anonymousExport" | "noExport" | "localComponents" | "reactContext", [] | [OnlyExportComponentsOptions] > ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.