+ {items.map((item) => (
+
setSelection(item)}>
+ {item.name}
+
+ ))}
+
+ )
+ }
+ `,
+ errors: [
+ {
+ messageId: "noDirectSetStateInUseEffect",
+ },
+ ],
+ },
+ {
+ name: "Conditionally setting state from internal state",
+ code: tsx`
+ function Form() {
+ const [error, setError] = useState();
+ const [result, setResult] = useState();
+
+ useEffect(() => {
+ if (result.data) {
+ setError(null);
+ }
+ }, [result]);
+ }
+ `,
+ errors: [
+ {
+ messageId: "noDirectSetStateInUseEffect",
+ },
+ ],
+ },
],
valid: [
...allValid,
@@ -996,5 +1046,34 @@ ruleTester.run(RULE_NAME, rule, {
}, [])
}
`,
+ tsx`
+ import { useEffect, useState, useCallback } from "react";
+
+ function useCustomHook() {
+ useLayoutEffect(() => {
+ navigation.setOptions({
+ headerLeft: () =>