r/reactjs • u/nickjvandyke • Jun 08 '26
Resource ESLint plugin to catch unnecessary effects v1.0.0: new rule, clearer messages, better signal-to-noise, more stable internals, and oxlint support
https://github.com/nickjvandyke/eslint-plugin-react-you-might-not-need-an-effectHello! I'm excited to share v1.0.0 of my ESLint plugin that catches unnecessary React effects for simpler, faster, safer code! It's been a while and I've made too many improvements to cover here (check CHANGELOG.md!), but these are the major ones.
Semantically, the bump to v1.0.0 also means I feel confident in the plugin's reliability and stability π
Thanks in advance for reading, and I hope it helps you! Please feel free to share feedback, I am always looking for opportunities for improvement π It's thanks to the community that I was able to iterate this far!
New rule: no-external-store-subscription
The final missing rule (relative to React's official docs). Disallows subscribing to an external store in an effect. While effects are meant to sync with external systems, useSyncExternalStore is better.
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);
};
}, []);
}Clearer messages
I added specific context to every rule message for clarity and actionability, and now account for whether we are inside a component or custom hook, because that affects the solution.
const ChildInput = ({ onTextChanged }) => {
const [text, setText] = useState();
useEffect(() => {
// π Before: Avoid passing live state to parents in an
// effect. Instead, lift the state to the parent and pass
// it down to the child as a prop.
// π After: Avoid passing live state to parents in an
// effect. Instead, lift "text" to the parent and pass
// it down to "ChildInput" as a prop.
onTextChanged(text);
}, [onTextChanged, text]);
return (
<input onChange={(e) => setText(e.target.value)} />
);
}
const useMyCustomHook = ({ onTextChanged }) => {
const [text, setText] = useState();
useEffect(() => {
// π Before: Avoid passing live state to parents in an
// effect. Instead, lift the state to the parent and pass
// it down to the child as a prop.
// π After: Avoid passing live state to parents in an effect.
// Instead, return "text" from "useMyCustomHook".
onTextChanged(text);
}, [onTextChanged, text]);
// ...
}Better signal-to-noise ratio
I relaxed some upstream assumptions when determining whether a variable is state/props/ref. It caught unusual syntax, but caused false-positives on more common patterns like useQuery.
I also rounded out interpreting uncommon syntax, such as aliased variables, named functions passed to effects, and separately-wrapped HOCs.
TypeScript + tsdown
I migrated the code to TypeScript and the build system to tsdown for more reliable internals. If you maintain a JS/TS library, I highly recommend tsdown; it simplified and automated so much of what makes JS/TS libraries a headache (ESM vs CJS module resolution, type resolution, and publish verification). Huge thanks to VoidZero for this utility.
Oxlint support
This is also thanks to VoidZero's amazing work to make ESLint plugins compatible with Oxlint! But I've verified it and added setup docs.
16
u/michaelfrieze Jun 08 '26
I've been using this eslint plugin for about a month and it's been great. It helps GPT-5.5 and Composer 2.5 write much better react code.
11
u/sebastienlorber Jun 08 '26
Hey!
LGTM and already featured last week in my newsletter (thisweekinreact.com)
IMHO you should write a blog post or better release notes, because afaik outside of this post we barely have any context about this release in your changelog or release notes:
- https://github.com/nickjvandyke/eslint-plugin-react-you-might-not-need-an-effect/releases/tag/v1.0.0
- https://github.com/nickjvandyke/eslint-plugin-react-you-might-not-need-an-effect/blob/main/CHANGELOG.md
3
u/kitchen Jun 08 '26
any plans to add Biome support?
2
u/kitkatas Jun 08 '26
Could a test be done on a large open source monorepo whenever this plugin generates false positives?
So far, though, I love the initiative!
1
u/anonyuser415 Jun 08 '26
surely there's better justification than this
what benefit does the code gain in this post's example from switching, beyond "doesn't error on the plugin I made"
2
u/Pauli444 Jul 25 '26
Thanks, i wanted to migrate my projects to oxlint, but I was worried about less react plugins. I am gnna try to setup oxlint with your plugin!