Skip to content

Commit 570e665

Browse files
committed
Add docs
1 parent 5a5d0c6 commit 570e665

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ export default observer(Foo);
2222

2323
Thanks @HorusGoul!
2424

25+
### Add recommended config and simple types (#67)
26+
27+
You can now add the recommended config to your ESLint config like this:
28+
29+
```js
30+
import reactRefresh from "eslint-plugin-react-refresh";
31+
32+
export default [
33+
/* Main config */
34+
reactRefresh.configs.recommended, // Or reactRefresh.configs.vite for Vite users
35+
];
36+
```
37+
38+
To follow ESLint recommandations, the rule is added with the `error` severity.
39+
40+
Some simple types ensure that people typecheking their config won't need `@ts-expect-error` anymore.
41+
2542
### Bump ESLint peer dependency to 8.40
2643

2744
This was actually done by mistake in the previous release when moving from a deprecated API to a new one.

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# eslint-plugin-react-refresh [![npm](https://img.shields.io/npm/v/eslint-plugin-react-refresh)](https://www.npmjs.com/package/eslint-plugin-react-refresh)
22

3-
Validate that your components can safely be updated with fast refresh.
3+
Validate that your components can safely be updated with Fast Refresh.
44

55
## Explainer
66

7-
"Fast refresh", also known as "hot reloading", is a feature in many modern bundlers.
7+
"Fast Refresh", also known as "hot reloading", is a feature in many modern bundlers.
88
If you update some React component(s) on disk, then the bundler will know to update only the impacted parts of your page -- without a full page reload.
99

1010
`eslint-plugin-react-refresh` enforces that your components are structured in a way that integrations such as [react-refresh](https://www.npmjs.com/package/react-refresh) expect.
@@ -28,7 +28,33 @@ npm i -D eslint-plugin-react-refresh
2828

2929
## Usage
3030

31-
This plugin provides a single rule, `react-refresh/only-export-components`.
31+
This plugin provides a single rule, `react-refresh/only-export-components`. There are multiple ways to enable it.
32+
33+
### Recommended config
34+
35+
```js
36+
import reactRefresh from "eslint-plugin-react-refresh";
37+
38+
export default [
39+
/* Main config */
40+
reactRefresh.configs.recommended,
41+
];
42+
```
43+
44+
### Vite config
45+
46+
This enables the `allowConstantExport` option which is supported by Vite React plugins.
47+
48+
```js
49+
import reactRefresh from "eslint-plugin-react-refresh";
50+
51+
export default [
52+
/* Main config */
53+
reactRefresh.configs.vite,
54+
];
55+
```
56+
57+
### Without config
3258

3359
```js
3460
import reactRefresh from "eslint-plugin-react-refresh";
@@ -111,7 +137,6 @@ These options are all present on `react-refresh/only-exports-components`.
111137

112138
```ts
113139
interface Options {
114-
allowExportNames?: string[];
115140
allowExportNames?: string[];
116141
allowConstantExport?: boolean;
117142
customHOCs?: string[];
@@ -145,7 +170,7 @@ Example for [Remix](https://remix.run/docs/en/main/discussion/hot-module-replace
145170

146171
### allowConstantExport <small>(v0.4.0)</small>
147172

148-
> Default: `false`
173+
> Default: `false` (`true` in `vite` config)
149174
150175
Don't warn when a constant (string, number, boolean, templateLiteral) is exported aside one or more components.
151176

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
type Config = {
2-
plugins: { "react-refresh": any };
2+
plugins: { "react-refresh": { rules: Record<string, any> } };
33
rules: Record<string, any>;
44
};
55

66
declare const _default: {
7-
rules: { "only-export-components": any };
7+
rules: Record<string, any>;
88
configs: {
99
recommended: Config;
1010
vite: Config;

0 commit comments

Comments
 (0)