title: How to setState inside an api function
body: <p>I have this code inside a class method:</p>
  <pre><code>ref
        .orderByValue()
        .equalTo(email)
        .once(&quot;value&quot;, snapshot =&gt; {
          if (snapshot.exists()) {
            console.log(this);
            this.setState({ signedUp: true });
          } else {
            ref.update({ [newKey]: email });
          }
        });
  </code></pre>
  <p>It's going to update my Firebase database on submit, unless the user has already signed up. A typeError says <code>this.setState is not a function</code>. But when I console log <code>this</code>, the console prints out the class. Logging <code>this.state</code> also prints out the state.</p>
  <p>How do I fix this? I want to update my state from inside this function.</p>