π ββοΈ Catch unnecessary React effects for simpler, faster, safer code.
JavaScript
1,921
550 commits
updated Sep 24, 2026
ESLint (and Oxlint) plugin to catch unnecessary useEffects to make your React code easier to follow, faster to run, and less error-prone. Highly recommended for new React developers as you learn React's mental model. Even experienced developers will likely learn something new!
function Form() {
const [firstName, setFirstName] = useState("Nick");
const [lastName, setLastName] = useState("van Dyke");
const [fullName, setFullName] = useState("");
useEffect(() => {
// β Avoid storing derived state. Instead, compute "fullName" directly during render.
// π react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state
setFullName(firstName + " " + lastName);
}, [firstName, lastName]);
}
React's
eslint-plugin-react-hooks/set-state-in-effectrule flags synchronoussetStatecalls inside effects, helping prevent unnecessary re-renders. However, unnecessary effects go far beyond this.
npm install --save-dev eslint-plugin-react-you-might-not-need-an-effect
yarn add -D eslint-plugin-react-you-might-not-need-an-effect
// eslint.config.js
import reactYouMightNotNeedAnEffect from "eslint-plugin-react-you-might-not-need-an-effect";
import globals from "globals";
export default [
// Enable every rule as a warning
reactYouMightNotNeedAnEffect.configs.recommended,
// Or enable every rule as an error
reactYouMightNotNeedAnEffect.configs.strict,
// Or enable only specific rules
{
plugins: {
reactYouMightNotNeedAnEffect,
},
rules: {
"reactYouMightNotNeedAnEffect/no-derived-state": "warn",
},
languageOptions: {
globals: {
...globals.browser,
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
},
];
// .eslintrc
{
"extends": [
// Enable every rule as a warning
"plugin:react-you-might-not-need-an-effect/legacy-recommended",
// Or enable every rule as an error
"plugin:react-you-might-not-need-an-effect/legacy-strict",
],
// Or enable only specific rules
"plugins": ["react-you-might-not-need-an-effect"],
"rules": {
"react-you-might-not-need-an-effect/no-derived-state": "warn",
},
"env": {
"browser": true,
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
},
},
}
Use this plugin with Oxlint thanks to their JS plugin support!
// .oxlintrc.json
{
"jsPlugins": ["eslint-plugin-react-you-might-not-need-an-effect"],
"rules": {
"react-you-might-not-need-an-effect/no-derived-state": "warn",
"react-you-might-not-need-an-effect/no-chain-state-updates": "warn",
"react-you-might-not-need-an-effect/no-event-handler": "warn",
"react-you-might-not-need-an-effect/no-adjust-state-on-prop-change": "warn",
"react-you-might-not-need-an-effect/no-reset-all-state-on-prop-change": "warn",
"react-you-might-not-need-an-effect/no-pass-live-state-to-parent": "warn",
"react-you-might-not-need-an-effect/no-pass-data-to-parent": "warn",
"react-you-might-not-need-an-effect/no-external-store-subscription": "warn",
"react-you-might-not-need-an-effect/no-initialize-state": "warn",
},
"env": {
"browser": true,
},
}
Enforce these other rules in your codebase for more accurate analysis:
react-hooks/exhaustive-deps β the plugin assumes your effects receive correct dependencies.typescript-eslint/no-floating-promises β helps the plugin infer calls to asynchronous functions.See the tests for extensive (in)valid examples for each rule.
Disallow storing derived state in an effect:
function Form() {
const [firstName, setFirstName] = useState("Nick");
const [lastName, setLastName] = useState("van Dyke");
const [fullName, setFullName] = useState("");
useEffect(() => {
// β Avoid storing derived state. Instead, compute "fullName" directly during render.
setFullName(firstName + " " + lastName);
}, [firstName, lastName]);
}
Disallow chaining state updates in an effect:
function Game() {
const [round, setRound] = useState(1);
const [isGameOver, setIsGameOver] = useState(false);
useEffect(() => {
if (round > 10) {
// β Avoid chaining state changes. When possible, update "isGameOver" along with other relevant state simultaneously.
setIsGameOver(true);
}
}, [round]);
}
Disallow using state and an effect as an event handler:
function Form() {
const [dataToSubmit, setDataToSubmit] = useState();
useEffect(() => {
if (dataToSubmit) {
// β Avoid using state and effects as an event handler. Instead, call the code that uses "dataToSubmit" directly when the event occurs.
submitData(dataToSubmit);
}
}, [dataToSubmit]);
}
Disallow using props and an effect as an event handler:
function ProductPage({ product, addToCart }) {
useEffect(() => {
if (product.isInCart) {
// β Avoid using props and effects as an event handler. Instead, move the code that uses "product" to the parent component.
showNotification(`Added ${product.name} to the shopping cart!`);
}
}, [product]);
}
Disallow adjusting state in an effect when a prop changes:
function List({ items }) {
const [isReverse, setIsReverse] = useState(false);
const [selection, setSelection] = useState(null);
useEffect(() => {
// β Avoid adjusting state when a prop changes. Instead, adjust "selection" directly during render when "items" changes, or refactor your state to avoid this need entirely.
setSelection(null);
}, [items]);
}
Disallow resetting all state in an effect when a prop changes:
function List({ items }) {
const [selection, setSelection] = useState(null);
useEffect(() => {
// β Avoid resetting all state when a prop changes. If "items" is a key, pass it as "key" instead so React will reset the component.
setSelection(null);
}, [items]);
}
Disallow passing live state to parents in an effect from a component:
function Child({ onTextChanged }) {
const [text, setText] = useState();
useEffect(() => {
// β Avoid passing live state to parents in an effect. Instead, lift "text" to the parent and pass it down to "Child" as a prop.
onTextChanged(text);
}, [onTextChanged, text]);
}
Disallow passing live state to parents in an effect from a custom hook:
const useCustomHook = ({ onTextChanged }) => {
const [text, setText] = useState();
useEffect(() => {
// β Avoid passing live state to parents in an effect. Instead, return "text" from "useCustomHook".
onTextChanged(text);
}, [onTextChanged, text]);
};
Disallow passing data to parents in an effect from a component:
function Child({ onDataFetched }) {
const { data } = useQuery("/data");
useEffect(() => {
// β Avoid passing data to parents in an effect. Instead, fetch "useQuery" in the parent and pass it down to "Child" as a prop.
onDataFetched(data);
}, [data, onDataFetched]);
}
Disallow passing data to parents in an effect from a custom hook:
const useCustomHook = ({ onFetched }) => {
const data = useSomeAPI();
useEffect(() => {
// β Avoid passing data to parents in an effect. Instead, return "useSomeAPI" from "useCustomHook".
onFetched(data);
}, [onFetched, data]);
};
Disallow subscribing to an external store in an effect:
function useOnlineStatus() {
const [isOnline, setIsOnline] = useState(true);
useEffect(() => {
function updateState() {
setIsOnline(navigator.onLine);
}
updateState();
window.addEventListener("online", updateState);
window.addEventListener("offline", updateState);
return () => {
// β Avoid using an effect to subscribe to an external store. Instead, use "useSyncExternalStore" to manage "isOnline".
window.removeEventListener("online", updateState);
window.removeEventListener("offline", updateState);
};
}, []);
}
Disallow initializing state in an effect:
function Component() {
const [state, setState] = useState();
useEffect(() => {
// β Avoid initializing state in an effect. Instead, initialize "state"'s "useState()" with "Hello World". For SSR hydration, prefer "useSyncExternalStore".
setState("Hello World");
}, []);
}
The ways to (mis)use an effect in real-world code are practically endless! This plugin is not exhaustive, but tries to be. If you encounter unexpected behavior or see opportunities for improvement, please open an issue or pull request. Your feedback helps improve the plugin for everyone!
Deep-dives from the official React documentation:
Latest release
Releases this year
(top 24 of 46)
1,983 followers Β· starred Jun 2025
973 followers Β· starred Jun 2025
345 followers Β· starred Aug 2026
122 followers Β· starred May 2025
π ββοΈ Catch unnecessary React effects for simpler, faster, safer code.
JavaScript
1,921
550 commits
updated Sep 24, 2026
ESLint (and Oxlint) plugin to catch unnecessary useEffects to make your React code easier to follow, faster to run, and less error-prone. Highly recommended for new React developers as you learn React's mental model. Even experienced developers will likely learn something new!
function Form() {
const [firstName, setFirstName] = useState("Nick");
const [lastName, setLastName] = useState("van Dyke");
const [fullName, setFullName] = useState("");
useEffect(() => {
// β Avoid storing derived state. Instead, compute "fullName" directly during render.
// π react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state
setFullName(firstName + " " + lastName);
}, [firstName, lastName]);
}
React's
eslint-plugin-react-hooks/set-state-in-effectrule flags synchronoussetStatecalls inside effects, helping prevent unnecessary re-renders. However, unnecessary effects go far beyond this.
npm install --save-dev eslint-plugin-react-you-might-not-need-an-effect
yarn add -D eslint-plugin-react-you-might-not-need-an-effect
// eslint.config.js
import reactYouMightNotNeedAnEffect from "eslint-plugin-react-you-might-not-need-an-effect";
import globals from "globals";
export default [
// Enable every rule as a warning
reactYouMightNotNeedAnEffect.configs.recommended,
// Or enable every rule as an error
reactYouMightNotNeedAnEffect.configs.strict,
// Or enable only specific rules
{
plugins: {
reactYouMightNotNeedAnEffect,
},
rules: {
"reactYouMightNotNeedAnEffect/no-derived-state": "warn",
},
languageOptions: {
globals: {
...globals.browser,
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
},
];
// .eslintrc
{
"extends": [
// Enable every rule as a warning
"plugin:react-you-might-not-need-an-effect/legacy-recommended",
// Or enable every rule as an error
"plugin:react-you-might-not-need-an-effect/legacy-strict",
],
// Or enable only specific rules
"plugins": ["react-you-might-not-need-an-effect"],
"rules": {
"react-you-might-not-need-an-effect/no-derived-state": "warn",
},
"env": {
"browser": true,
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
},
},
}
Use this plugin with Oxlint thanks to their JS plugin support!
// .oxlintrc.json
{
"jsPlugins": ["eslint-plugin-react-you-might-not-need-an-effect"],
"rules": {
"react-you-might-not-need-an-effect/no-derived-state": "warn",
"react-you-might-not-need-an-effect/no-chain-state-updates": "warn",
"react-you-might-not-need-an-effect/no-event-handler": "warn",
"react-you-might-not-need-an-effect/no-adjust-state-on-prop-change": "warn",
"react-you-might-not-need-an-effect/no-reset-all-state-on-prop-change": "warn",
"react-you-might-not-need-an-effect/no-pass-live-state-to-parent": "warn",
"react-you-might-not-need-an-effect/no-pass-data-to-parent": "warn",
"react-you-might-not-need-an-effect/no-external-store-subscription": "warn",
"react-you-might-not-need-an-effect/no-initialize-state": "warn",
},
"env": {
"browser": true,
},
}
Enforce these other rules in your codebase for more accurate analysis:
react-hooks/exhaustive-deps β the plugin assumes your effects receive correct dependencies.typescript-eslint/no-floating-promises β helps the plugin infer calls to asynchronous functions.See the tests for extensive (in)valid examples for each rule.
Disallow storing derived state in an effect:
function Form() {
const [firstName, setFirstName] = useState("Nick");
const [lastName, setLastName] = useState("van Dyke");
const [fullName, setFullName] = useState("");
useEffect(() => {
// β Avoid storing derived state. Instead, compute "fullName" directly during render.
setFullName(firstName + " " + lastName);
}, [firstName, lastName]);
}
Disallow chaining state updates in an effect:
function Game() {
const [round, setRound] = useState(1);
const [isGameOver, setIsGameOver] = useState(false);
useEffect(() => {
if (round > 10) {
// β Avoid chaining state changes. When possible, update "isGameOver" along with other relevant state simultaneously.
setIsGameOver(true);
}
}, [round]);
}
Disallow using state and an effect as an event handler:
function Form() {
const [dataToSubmit, setDataToSubmit] = useState();
useEffect(() => {
if (dataToSubmit) {
// β Avoid using state and effects as an event handler. Instead, call the code that uses "dataToSubmit" directly when the event occurs.
submitData(dataToSubmit);
}
}, [dataToSubmit]);
}
Disallow using props and an effect as an event handler:
function ProductPage({ product, addToCart }) {
useEffect(() => {
if (product.isInCart) {
// β Avoid using props and effects as an event handler. Instead, move the code that uses "product" to the parent component.
showNotification(`Added ${product.name} to the shopping cart!`);
}
}, [product]);
}
Disallow adjusting state in an effect when a prop changes:
function List({ items }) {
const [isReverse, setIsReverse] = useState(false);
const [selection, setSelection] = useState(null);
useEffect(() => {
// β Avoid adjusting state when a prop changes. Instead, adjust "selection" directly during render when "items" changes, or refactor your state to avoid this need entirely.
setSelection(null);
}, [items]);
}
Disallow resetting all state in an effect when a prop changes:
function List({ items }) {
const [selection, setSelection] = useState(null);
useEffect(() => {
// β Avoid resetting all state when a prop changes. If "items" is a key, pass it as "key" instead so React will reset the component.
setSelection(null);
}, [items]);
}
Disallow passing live state to parents in an effect from a component:
function Child({ onTextChanged }) {
const [text, setText] = useState();
useEffect(() => {
// β Avoid passing live state to parents in an effect. Instead, lift "text" to the parent and pass it down to "Child" as a prop.
onTextChanged(text);
}, [onTextChanged, text]);
}
Disallow passing live state to parents in an effect from a custom hook:
const useCustomHook = ({ onTextChanged }) => {
const [text, setText] = useState();
useEffect(() => {
// β Avoid passing live state to parents in an effect. Instead, return "text" from "useCustomHook".
onTextChanged(text);
}, [onTextChanged, text]);
};
Disallow passing data to parents in an effect from a component:
function Child({ onDataFetched }) {
const { data } = useQuery("/data");
useEffect(() => {
// β Avoid passing data to parents in an effect. Instead, fetch "useQuery" in the parent and pass it down to "Child" as a prop.
onDataFetched(data);
}, [data, onDataFetched]);
}
Disallow passing data to parents in an effect from a custom hook:
const useCustomHook = ({ onFetched }) => {
const data = useSomeAPI();
useEffect(() => {
// β Avoid passing data to parents in an effect. Instead, return "useSomeAPI" from "useCustomHook".
onFetched(data);
}, [onFetched, data]);
};
Disallow subscribing to an external store in an effect:
function useOnlineStatus() {
const [isOnline, setIsOnline] = useState(true);
useEffect(() => {
function updateState() {
setIsOnline(navigator.onLine);
}
updateState();
window.addEventListener("online", updateState);
window.addEventListener("offline", updateState);
return () => {
// β Avoid using an effect to subscribe to an external store. Instead, use "useSyncExternalStore" to manage "isOnline".
window.removeEventListener("online", updateState);
window.removeEventListener("offline", updateState);
};
}, []);
}
Disallow initializing state in an effect:
function Component() {
const [state, setState] = useState();
useEffect(() => {
// β Avoid initializing state in an effect. Instead, initialize "state"'s "useState()" with "Hello World". For SSR hydration, prefer "useSyncExternalStore".
setState("Hello World");
}, []);
}
The ways to (mis)use an effect in real-world code are practically endless! This plugin is not exhaustive, but tries to be. If you encounter unexpected behavior or see opportunities for improvement, please open an issue or pull request. Your feedback helps improve the plugin for everyone!
Deep-dives from the official React documentation:
Latest release
Releases this year
(top 24 of 46)
1,983 followers Β· starred Jun 2025
973 followers Β· starred Jun 2025
345 followers Β· starred Aug 2026
122 followers Β· starred May 2025