## Common Answers

💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡

**We analyzed the comments on this post to provide some guidance: https://github.com/facebook/react/issues/14920#issuecomment-471070149.**

💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡💡

----

## What is this

This is a new ESLint rule that verifies the list of dependencies for Hooks like `useEffect` and similar, protecting against the stale closure pitfalls. For most cases it has an autofix. We'll add more documentation over the next weeks.

![autofix demo](https://user-images.githubusercontent.com/810438/54288712-d3615a00-459f-11e9-82a6-904442995d2f.gif)


## Installation

```
yarn add eslint-plugin-react-hooks@next
# or
npm install eslint-plugin-react-hooks@next
```

ESLint config:

```js
{
  "plugins": ["react-hooks"],
  // ...
  "rules": {
    "react-hooks/rules-of-hooks": 'error',
    "react-hooks/exhaustive-deps": 'warn' // <--- THIS IS THE NEW RULE
  }
}
```

Simple test case to verify the rule works:

```js
function Foo(props) {
  useEffect(() => {
    console.log(props.name);
  }, []); // <-- should error and offer autofix to [props.name]
}
``` 
## The lint rule complains but my code is fine!

**If this new `react-hooks/exhaustive-deps` lint rule fires for you but you think your code is correct**, please post in this issue.

----



# BEFORE YOU POST A COMMENT

**Please** include these three things:

1. A CodeSandbox demonstrating a **minimal code example** that still expresses your intent (not "foo bar" but **actual UI pattern** you're implementing).
2. An explanation of the **steps** a user does and what you expect to see on the screen.
3. An explanation of the **intended API** of your Hook/component.

![please](https://media1.giphy.com/media/14cNSEhRyTX8Ag/giphy.gif?cid=3640f6095c700c9b774a644a51e2089e)

## But my case is simple, I don't want to include those things!

It might be simple to you — but it’s not at all simple to us. **If your comment doesn't include either of them (e.g. no CodeSandbox link), we will hide your comment** because it’s very hard to track the discussion otherwise. Thank you for respecting everyone’s time by including them.

The end goal of this thread is to find common scenarios and transform them into better docs and warnings. This can only happen when enough details are available. Drive-by comments with incomplete code snippets significantly drive down the quality of the discussion — to the point that it's not worth it.
const myRef = useRef();
          useEffect(() => {
            const handleMove = () => {
              console.log(myRef.current)
            };
            window.addEventListener('mousemove', handleMove);
            return () => window.removeEventListener('mousemove', handleMove);
          }, []);
          return <div ref={myRef} />;
        }
      `,
    },
    {
      
      code: `
        function useMyThing() {
          const myRef = useRef();
          useEffect(() => {
            const handleMove = () => {
              return () => window.removeEventListener('mousemove', handleMove);
            };
            window.addEventListener('mousemove', handleMove);
            return () => {};
          }, []);
          return <div ref={myRef} />;
        }
      `,
    },
    {