source: imaps-frontend/node_modules/eslint-plugin-react-refresh/README.md

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.3 KB
Line 
1# eslint-plugin-react-refresh [![npm](https://img.shields.io/npm/v/eslint-plugin-react-refresh)](https://www.npmjs.com/package/eslint-plugin-react-refresh)
2
3Validate that your components can safely be updated with fast refresh.
4
5## Limitations
6
7⚠️ To avoid false positive, by default this plugin is only applied on `tsx` & `jsx` files. See options to run on JS files. ⚠️
8
9The plugin rely on naming conventions (i.e. use PascalCase for components, camelCase for util functions). This is why there are some limitations:
10
11- `export *` are not supported and will be reported as an error
12- Anonymous function are not supported (i.e `export default function() {}`)
13- Class components are not supported
14- All-uppercase function export is considered an error when not using direct named export (ex `const CMS = () => <></>; export { CMS }`)
15
16## Installation
17
18```sh
19npm i -D eslint-plugin-react-refresh
20```
21
22## Usage
23
24```json
25{
26 "plugins": ["react-refresh"],
27 "rules": {
28 "react-refresh/only-export-components": "warn"
29 }
30}
31```
32
33### Flat config
34
35```js
36import reactRefresh from "eslint-plugin-react-refresh";
37
38export default [
39 {
40 // in main config for TSX/JSX source files
41 plugins: {
42 "react-refresh": reactRefresh,
43 },
44 rules: {
45 "react-refresh/only-export-components": "warn",
46 },
47 },
48];
49```
50
51## Fail
52
53```jsx
54export const foo = () => {};
55export const Bar = () => <></>;
56```
57
58```jsx
59export default function () {}
60export default compose()(MainComponent)
61```
62
63```jsx
64export * from "./foo";
65```
66
67```jsx
68const Tab = () => {};
69export const tabs = [<Tab />, <Tab />];
70```
71
72```jsx
73const App = () => {};
74createRoot(document.getElementById("root")).render(<App />);
75```
76
77## Pass with allowConstantExport
78
79```jsx
80export const CONSTANT = 3;
81export const Foo = () => <></>;
82```
83
84## Pass
85
86```jsx
87export default function Foo() {
88 return <></>;
89}
90```
91
92```jsx
93const foo = () => {};
94export const Bar = () => <></>;
95```
96
97```jsx
98import { App } from "./App";
99createRoot(document.getElementById("root")).render(<App />);
100```
101
102## Options
103
104### allowExportNames <small>(v0.4.4)</small>
105
106If you use a framework that handles HMR of some specific exports, you can use this option to avoid warning for them.
107
108Example for [Remix](https://remix.run/docs/en/main/other-api/dev#:~:text=React%20Fast%20Refresh,-can%20only%20handle):
109
110```json
111{
112 "react-refresh/only-export-components": [
113 "warn",
114 { "allowExportNames": ["meta", "links", "headers", "loader", "action"] }
115 ]
116}
117```
118
119### allowConstantExport <small>(v0.4.0)</small>
120
121Don't warn when a constant (string, number, boolean, templateLiteral) is exported aside one or more components.
122
123This 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.
124
125```json
126{
127 "react-refresh/only-export-components": [
128 "warn",
129 { "allowConstantExport": true }
130 ]
131}
132```
133
134### checkJS <small>(v0.3.3)</small>
135
136If 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.
137
138```json
139{
140 "react-refresh/only-export-components": ["warn", { "checkJS": true }]
141}
142```
Note: See TracBrowser for help on using the repository browser.