Skip to content

Bug: eslint(react-hooks/set-state-in-effect) not work with try catch function #34998

@757566833

Description

@757566833

React version: 19.2

Steps To Reproduce

Image

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>
}

The current behavior

eslint not work

The expected behavior

eslint work

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions