-
-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Describe the problem
Hi @Rel1cx, thanks for this plugin, amazing!
I'm looking to ban the usage of symmetrical set functions in useEffect without banning set functions entirely:
Only setLimit would be a reported problem (because of the limit in the dependency array), not setItems
import { useEffect, useState } from 'react';
function List({ items }) {
const [items, setItems] = useState([]);
const [limit, setLimit] = useState(false);
useEffect(() => {
setLimit(/* ... */);
setItems(/* ... */);
}, [limit]);
// ...
}Describe the solution you'd like
A new option (default true? would be a breaking change though) to only check for symmetrical setters
Maybe this also affects no-direct-symmetrical-set-state-in-use-layout-effect?
Alternatives considered
A new rule no-direct-symmetrical-set-state-in-use-effect (maybe also no-direct-symmetrical-set-state-in-use-layout-effect?)
Additional context
This would be a less strict rule that would catch a lot of infinite loop patterns without restricting set functions for use cases that can make sense
Use case: teaching students to avoid infinite loops while not being overly strict: