You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58-23Lines changed: 58 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,18 @@
2
2
3
3
Validate that your components can safely be updated with fast refresh.
4
4
5
-
## Limitations
5
+
## Explainer
6
6
7
-
⚠️ To avoid false positive, by default this plugin is only applied on `tsx` & `jsx` files. See options to run on JS files. ⚠️
7
+
"Fast refresh", also known as "hot reloading", is a feature in many modern bundlers.
8
+
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.
8
9
9
-
The plugin rely on naming conventions (i.e. use PascalCase for components, camelCase for util functions). This is why there are some limitations:
10
+
`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.
11
+
12
+
### Limitations
13
+
14
+
⚠️ To avoid false positives, by default this plugin is only applied on `tsx` & `jsx` files. See [Options](#options) to run on JS files. ⚠️
15
+
16
+
The plugin relies on naming conventions (i.e. use PascalCase for components, camelCase for util functions). This is why there are some limitations:
10
17
11
18
-`export *` are not supported and will be reported as an error
12
19
- Anonymous function are not supported (i.e `export default function() {}`)
@@ -21,16 +28,7 @@ npm i -D eslint-plugin-react-refresh
21
28
22
29
## Usage
23
30
24
-
```json
25
-
{
26
-
"plugins": ["react-refresh"],
27
-
"rules": {
28
-
"react-refresh/only-export-components": "warn"
29
-
}
30
-
}
31
-
```
32
-
33
-
### Flat config
31
+
This plugin provides a single rule, `react-refresh/only-export-components`.
These options are all present on `react-refresh/only-exports-components`.
111
+
112
+
```ts
113
+
interfaceOptions {
114
+
allowExportNames?:string[];
115
+
allowConstantExport?:boolean;
116
+
checkJS?:boolean;
117
+
}
118
+
119
+
const defaultOptions:Options= {
120
+
allowExportNames: [],
121
+
allowConstantExport: false,
122
+
checkJS: false,
123
+
};
124
+
```
125
+
104
126
### allowExportNames <small>(v0.4.4)</small>
105
127
128
+
> Default: `[]`
129
+
106
130
If you use a framework that handles HMR of some specific exports, you can use this option to avoid warning for them.
107
131
108
-
Example for [Remix](https://remix.run/docs/en/main/other-api/dev#:~:text=React%20Fast%20Refresh,-can%20only%20handle):
132
+
Example for [Remix](https://remix.run/docs/en/main/discussion/hot-module-replacement#supported-exports):
109
133
110
134
```json
111
135
{
@@ -118,6 +142,8 @@ Example for [Remix](https://remix.run/docs/en/main/other-api/dev#:~:text=React%2
118
142
119
143
### allowConstantExport <small>(v0.4.0)</small>
120
144
145
+
> Default: `false`
146
+
121
147
Don't warn when a constant (string, number, boolean, templateLiteral) is exported aside one or more components.
122
148
123
149
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.
@@ -131,8 +157,17 @@ This should be enabled if the fast refresh implementation correctly handles this
131
157
}
132
158
```
133
159
160
+
Enabling this option allows code such as the following:
161
+
162
+
```jsx
163
+
exportconstCONSTANT=3;
164
+
exportconstFoo= () =><></>;
165
+
```
166
+
134
167
### checkJS <small>(v0.3.3)</small>
135
168
169
+
> Default: `false`
170
+
136
171
If your using JSX inside `.js` files (which I don't recommend because it forces you to configure every tool you use to switch the parser), you can still use the plugin by enabling this option. To reduce the number of false positive, only files importing `react` are checked.
0 commit comments