
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
eslint-plugin-react-hooks
Advanced tools
The eslint-plugin-react-hooks package is an ESLint plugin that enforces the Rules of Hooks for React. It helps developers to follow the best practices and avoid common pitfalls when using hooks in React components.
Rules of Hooks
This feature enforces the rules of hooks, ensuring that hooks are called in the same order on every render and not inside conditions, loops, or nested functions.
/* eslint react-hooks/rules-of-hooks: 'error' */
const MyComponent = () => {
if (condition) {
const [value, setValue] = useState(0); // This will cause an error
}
return <div>{value}</div>;
};
Exhaustive Dependencies
This feature ensures that all dependencies used inside useEffect, useCallback, and useMemo are properly specified, helping to avoid stale closures and other related bugs.
/* eslint react-hooks/exhaustive-deps: 'warn' */
useEffect(() => {
// Should include dependencies used inside the effect
}, []); // This will cause a warning if dependencies are omitted
This package includes linting rules for React and JSX. It is broader in scope than eslint-plugin-react-hooks, covering a wide range of React best practices and potential errors, not limited to hooks.
This is a less popular and potentially less maintained alternative to eslint-plugin-react-hooks. It may offer similar functionality but does not have the same level of community support or frequent updates.
eslint-plugin-react-hooks
This ESLint plugin enforces the Rules of Hooks.
It is a part of the Hooks API for React.
Note: If you're using Create React App, please use react-scripts
>= 3 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
If you are still using ESLint below 9.0.0, please continue to use recommended-legacy
. To avoid breaking changes, we still support recommended
as well, but note that this will be changed to alias the flat recommended config in v6.
{
"extends": [
// ...
"plugin:react-hooks/recommended-legacy"
]
}
For ESLint 9.0.0 and above users, add the recommended-latest
config.
import reactHooks from 'eslint-plugin-react-hooks';
export default [
// ...
reactHooks.configs['recommended-latest'],
];
If you want more fine-grained configuration, you can instead add a snippet like this to your ESLint configuration file:
{
"plugins": [
// ...
"react-hooks"
],
"rules": {
// ...
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
}
}
import reactHooks from 'eslint-plugin-react-hooks';
export default [
{
files: ['**/*.{js,jsx}'],
plugins: { 'react-hooks': reactHooks },
// ...
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
}
},
];
exhaustive-deps
can be configured to validate dependencies of custom Hooks with the additionalHooks
option.
This option accepts a regex to match the names of custom Hooks that have dependencies.
{
"rules": {
// ...
"react-hooks/exhaustive-deps": ["warn", {
"additionalHooks": "(useMyCustomHook|useMyOtherCustomHook)"
}]
}
}
We suggest to use this option very sparingly, if at all. Generally saying, we recommend most custom Hooks to not use the dependencies argument, and instead provide a higher-level API that is more focused around a specific use case.
Please refer to the Rules of Hooks documentation to learn more about this rule.
MIT
15.2.0 (July 1, 2016)
React.PropTypes.symbol
to support ES2015 Symbols as props. (@puradox in #6377)childContextTypes
on a functional component (@Aweary in #6933)onLoad
handling to <link>
element. (@roderickhsiao in #6815)onError
handling to <source>
element. (@wadahiro in #6941)value
and defaultValue
more accurately in the DOM. (@jimfb in #6406)Object.prototype
. (@Weizenlol in #6886)is="null"
ended up in the DOM in Firefox. (@darobin in #6896)dangerouslySetInnerHTML
and SVG in Internet Explorer. (@joshhunt in #6982)<textarea>
placeholders. (@jimfb in #7002)<input type="radio"/>
. (@jimfb in #7003)<select>
components behave the same on initial render as they do on updates. (@yiminghe in #5362)isRunning()
API. (@nfcampos in #6763)null
node. (@keyanzhang in #6958)FAQs
ESLint rules for React Hooks
The npm package eslint-plugin-react-hooks receives a total of 22,531,059 weekly downloads. As such, eslint-plugin-react-hooks popularity was classified as popular.
We found that eslint-plugin-react-hooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.