@@ -1408,15 +1408,32 @@ impl<'a> Visit<'a> for ExhaustiveDepsVisitor<'a, '_> {
14081408 if let Some ( decl) = get_declaration_of_variable ( ident, self . semantic ) {
14091409 let is_set_state_call = match decl. kind ( ) {
14101410 AstKind :: VariableDeclarator ( var_decl) => {
1411- if let Some ( Expression :: CallExpression ( call_expr) ) = & var_decl. init {
1412- if let Some ( name) = func_call_without_react_namespace ( call_expr) {
1413- name == "useState" || name == "useReducer"
1414- } else {
1415- false
1416- }
1417- } else {
1418- false
1411+ let Some ( Expression :: CallExpression ( call_expr) ) = & var_decl. init else {
1412+ return ;
1413+ } ;
1414+
1415+ let Some ( name) = func_call_without_react_namespace ( call_expr) else {
1416+ return ;
1417+ } ;
1418+
1419+ if name != "useState" && name != "useReducer" {
1420+ return ;
14191421 }
1422+
1423+ let BindingPatternKind :: ArrayPattern ( array_pat) = & var_decl. id . kind else {
1424+ return ;
1425+ } ;
1426+
1427+ let Some ( Some ( second_arg) ) = array_pat. elements . get ( 1 ) else {
1428+ return ;
1429+ } ;
1430+
1431+ let BindingPatternKind :: BindingIdentifier ( binding_ident) = & second_arg. kind
1432+ else {
1433+ return ;
1434+ } ;
1435+
1436+ binding_ident. name == ident. name
14201437 }
14211438 _ => false ,
14221439 } ;
@@ -2554,6 +2571,7 @@ fn test() {
25542571 r"function MyComponent(props) { useEffect(() => { console.log(props.foo!.bar) }, [props.foo!.bar]) }" ,
25552572 r"function MyComponent(props) { useEffect(() => { console.log((props.foo).bar) }, [props.foo!.bar]) }" ,
25562573 r"function MyComponent(props) { const external = {}; const y = useMemo(() => { const z = foo<typeof external>(); return z; }, []) }" ,
2574+ r#"function Test() { const [state, setState] = useState(); useEffect(() => { console.log("state", state); }); }"# ,
25572575 ] ;
25582576
25592577 let fail = vec ! [
0 commit comments