title: How remember that a React hooks component is unmounted, so can avoid state changes?
body: <p>With old class based React.js code, I can do like this, to remember that a component has been unmounted:</p>
  
  <pre><code>  componentWillUnmount: function() {
      this.isGone = true;
    },
  
    loadUsers: function() {
      Server.loadUsers(..., (response) =&gt; {
        if (this.isGone) return;
        ...
      });
    }
  </code></pre>
  
  <p><strong>How can one do the same thing, with hooks based components?</strong></p>
  
  <p>Here's a sample hooks function component, where I'm unsure about how to remember that it's been unmounted, so I can <code>return</code> before calling any <code>setSomeState</code>:</p>
  
  <pre><code>export const GroupMembers = React.createFactory(function(props) {
  
    const [membersOrNull, setMembers] = React.useState(null);
    let isGone = false;  // ? (se [222] below
  
    React.useEffect(() =&gt; {
      Server.listGroupMembers(someGroupId, (response) =&gt; {
       if (/* is unmounted ?? */) return;
       setMembers(response.members);
      });
      return () =&gt; { /* how remember is unmounted?
                        would isGone = true; work? */ };
    }, []);
  
    ...
  
    return ..., Button({ title: "Remove all members", onClick: () =&gt; {
      Server.removeAllMembers(someGroupId, () =&gt; {
       if (/* is unmounted ?? */) return;
       setMembers([]);
      });
    }});
  </code></pre>
  
  <p>I suppose I cannot use <code>const [isGone, setGone] = useState(false)</code> because I shouldn't try to access the state (read <code>isGone</code>) after has been unmounted. And if I <em>[222]</em> add a local <code>let isGone = false</code> inside the function, it seems to me that various callbacks created inside the function, will refer to different "instances" of this local variable, depending on in which different <code>GroupMembers(..)</code> invokation the different callbacks were created? or am I mistaken and this works? — Maybe I could create an outer wrapper function with a local <code>let isGone = false</code>, however, this adds another wrapping function and indentation :- /</p>