Fix CJS/ESM interop issue. Sorry everyone for the trouble.
By default, the rule only knows that memo
& forwardRef
function calls with return a React component. With this option, you can also allow extra function names like Mobx observer to make this code valid:
const Foo = () => <></>;
export default observer(Foo);
{
"react-refresh/only-export-components": [
"error",
{ "customHOCs": ["observer"] }
]
}
Thanks @HorusGoul!
You can now add the recommended config to your ESLint config like this:
import reactRefresh from "eslint-plugin-react-refresh";
export default [
/* Main config */
reactRefresh.configs.recommended, // Or reactRefresh.configs.vite for Vite users
];
To follow ESLint recommandations, the rule is added with the error
severity.
Some simple types ensure that people typecheking their config won't need @ts-expect-error
anymore.
This was actually done by mistake in the previous release when moving from a deprecated API to a new one.
Given that ESLint 8 is officialy end-of-life and the only report (#56) didn't get likes, I'm going forward and documenting the expected minimum version from ESLin in the package JSON so that people can get warning from their package manager.
- Warn if a context is exported alongside a component (fixes #53). Thanks @IgorAufricht!
- Support for
react-redux
connect (export default connect(mapStateToProps, mapDispatchToProps)(MyComponent)
) (fixes #51) - Support for Arbitrary Module Identifiers syntax (fixes #52)
- Support type assertion on default export (fixes #48)
- Add default export to fix usage with jiti (fixes #50)
- Ignore type exports (ex.
export type foo = string;
) (fixes #47)
- Support
function Foo() {}; export default React.memo(Foo)
(#46) (thanks @SukkaW!)
- Support
function Foo() {}; export default memo(Foo)
(fixes #44) (thanks @SukkaW!)
- Support
export const foo = -1
withallowConstantExport
(fixes #43)
- Support
export { Component as default }
(fixes #41)
- Ignore cypress test files (#39)
- Allow
TaggedTemplateExpression
for styled components (fixes #32)
- Add
allowExportNames
option (fixes #29) - Support memo default export function components (fixes #27)
- Warn on export expressions that are not React component (array, object, logical expression, ...) (fixes #26)
- Add warning for TS enums exports
- Fix typos in messages (#15, #16). Thanks @adamschachne & @janikga!
- Ignore
export type *
(fixes #12) - Support for all-uppercase function wrapped in forwardRef/memo (#11)
This option allow to 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.
This only works when using direct export. So this pattern doesn't warn anymore:
export const CMS = () => <></>;
But this one will still warn:
const CMS = () => <></>;
export default CMS;
Ignore stories files (*.stories.*
) (fixes #10)
Report default CallExpression exports (#7) (fixes #6)
This allows to report a warning for this kind of patterns that creates anonymous components:
export default compose()(MainComponent)
Add checkJS option (#5) (fixes #4)
Ignore test files (*.test.*
, *.spec.*
) (fixes #2)
Allow numbers in component names (fixes #1)
Report an error when a file that contains components that can't be fast-refreshed because:
- There are no export (entrypoint)
- Exports are not components
Doc only: Update limitations section README.md
- Fix TS import
- Document limitations
Initial release