mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
dab2fdbbbd
* Add ESLint rule for useEffect/useCallback/useMemo Hook dependencies * Fix ReactiveDependencies rule * fix lint errors * Support useLayoutEffect * Add some failing tests and comments * Gather dependencies in child scopes too * If we don't find foo.bar.baz in deps, try foo.bar, then foo * foo is enough for both foo.bar and foo.baz * Shorter rule name * Add fixable meta * Remove a bunch of code and start from scratch * [WIP] Only report errors from dependency array This results in nicer editing experience. Also has autofix. * Fix typo * [Temp] Skip all tests * Fix the first test * Revamp the test suite * Fix [foo] to include foo.bar * Don't suggest call expressions * Special case 'current' for refs * Don't complain about known static deps * Support useImperativeHandle * Better punctuation and formatting * More uniform message format * Treat React.useRef/useState/useReducer as static too * Add special message for ref.current * Add a TODO case * Alphabetize the autofix * Only alphabetize if it already was * Don't add static deps by default * Add an undefined variable case * Tweak wording * Rename to exhaustive-deps * Clean up / refactor a little bit
eslint-plugin-react-hooks
This ESLint plugin enforces the Rules of Hooks.
It is a part of the Hooks API for React.
Installation
Note: If you're using Create React App, please wait for a corresponding release of react-scripts that includes this rule instead of adding it directly.
Assuming you already have ESLint installed, run:
# npm
npm install eslint-plugin-react-hooks --save-dev
# yarn
yarn add eslint-plugin-react-hooks --dev
Then add it to your ESLint configuration:
{
"plugins": [
// ...
"react-hooks"
],
"rules": {
// ...
"react-hooks/rules-of-hooks": "error"
}
}
Valid and Invalid Examples
Please refer to the Rules of Hooks documentation and the Hooks FAQ to learn more about this rule.
License
MIT