@@ -1263,12 +1263,43 @@ const tests = {
12631263 }, [ref1, ref2, props.someOtherRefs, props.color]);
12641264 }
12651265 ` ,
1266- // TODO: special message for the ref case.
12671266 errors : [
12681267 "React Hook useEffect has missing dependencies: 'props.someOtherRefs' and 'props.color'. " +
12691268 'Either include them or remove the dependency array.' ,
12701269 ] ,
12711270 } ,
1271+ {
1272+ code : `
1273+ function MyComponent(props) {
1274+ const ref1 = useRef();
1275+ const ref2 = useRef();
1276+ useEffect(() => {
1277+ ref1.current.focus();
1278+ console.log(ref2.current.textContent);
1279+ alert(props.someOtherRefs.current.innerHTML);
1280+ fetch(props.color);
1281+ }, [ref1.current, ref2.current, props.someOtherRefs, props.color]);
1282+ }
1283+ ` ,
1284+ output : `
1285+ function MyComponent(props) {
1286+ const ref1 = useRef();
1287+ const ref2 = useRef();
1288+ useEffect(() => {
1289+ ref1.current.focus();
1290+ console.log(ref2.current.textContent);
1291+ alert(props.someOtherRefs.current.innerHTML);
1292+ fetch(props.color);
1293+ }, [props.someOtherRefs, props.color, ref1, ref2]);
1294+ }
1295+ ` ,
1296+ errors : [
1297+ "React Hook useEffect has unnecessary dependencies: 'ref1.current' and 'ref2.current'. " +
1298+ 'Either exclude them or remove the dependency array. ' +
1299+ "Mutable values like 'ref1.current' aren't valid dependencies " +
1300+ "because their mutation doesn't re-render the component." ,
1301+ ] ,
1302+ } ,
12721303 {
12731304 code : `
12741305 function MyComponent() {
@@ -1286,10 +1317,11 @@ const tests = {
12861317 }, [ref]);
12871318 }
12881319 ` ,
1289- // TODO: special message for the ref case.
12901320 errors : [
12911321 "React Hook useEffect has an unnecessary dependency: 'ref.current'. " +
1292- 'Either exclude it or remove the dependency array.' ,
1322+ 'Either exclude it or remove the dependency array. ' +
1323+ "Mutable values like 'ref.current' aren't valid dependencies " +
1324+ "because their mutation doesn't re-render the component." ,
12931325 ] ,
12941326 } ,
12951327 {
0 commit comments