ESLint rule behavior inconsistency with try/catch/finally blocks.
The issue involves inconsistent behavior of the ESLint rule `react-hooks/set-state-in-effect` when state updates are inside `useEffect` with `try/catch/finally` blocks. The rule fails to report errors in certain configurations, suggesting a gap in control-flow analysis. The problem appears to be related to ESLint's internal logic rather than React itself, making it unclear if this is a React-specific issue.
React version: 19.2
Link to code example:
const Demo = ()=>{
const [count, setCount] = useState(0);
useEffect(()=>{
setCount(123);
},[])
const handleClick = useCallback(()=>{
try {
console.log("do");
} catch (_error) {
console.log("error");
}finally{
console.log("finally");
}
},[])
return <div onClick={handleClick}>Demo {count}</div>
}
const Demo2 = ()=>{
const [count, setCount] = useState(0);
useEffect(()=>{
setCount(123);
},[])
return <div>Demo {count}</div>
}
eslint not work
eslint work
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!