Skip to content

Commit ddbfe2e

Browse files
calebmeracdlite
authored andcommitted
Add ESLint rule for React Hooks
1 parent acb4899 commit ddbfe2e

8 files changed

Lines changed: 1302 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# `eslint-plugin-react-hooks`
2+
3+
This ESLint plugin enforces the [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html).
4+
5+
It is a part of the [Hooks proposal](https://reactjs.org/docs/hooks-intro.html) for React.
6+
7+
## Experimental Status
8+
9+
This is an experimental release and is intended to be used for testing the Hooks proposal with React 16.7 alpha. The exact heuristics it uses may be adjusted.
10+
11+
The [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html) documentation contains a link to the technical RFC. Please leave a comment on the RFC if you have concerns or ideas about how this plugin should work.
12+
13+
## Installation
14+
15+
**Note: If you're using Create React App, please wait for a corresponding experimental release of `react-scripts` that includes this rule instead of adding it directly.**
16+
17+
Assuming you already have ESLint installed, run:
18+
19+
```sh
20+
# npm
21+
npm install eslint-plugin-react-hooks@next --save-dev
22+
23+
# yarn
24+
yarn add eslint-plugin-react-hooks@next --dev
25+
```
26+
27+
Then add it to your ESLint configuration:
28+
29+
```js
30+
{
31+
"plugins": [
32+
// ...
33+
"react-hooks"
34+
],
35+
"rules": {
36+
// ...
37+
"react-hooks/rules-of-hooks": "error"
38+
}
39+
}
40+
```
41+
42+
## Valid and Invalid Examples
43+
44+
Please refer to the [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html) documentation and the [Hooks FAQ](https://reactjs.org/docs/hooks-faq.html#what-exactly-do-the-lint-rules-enforce) to learn more about this rule.
45+
46+
## License
47+
48+
MIT

0 commit comments

Comments
 (0)