title: Can I change other pieces of state in a Recoil Atom Effect
body: <h2>The Situation</h2>
  <p>I am using <a href="https://recoiljs.org/" rel="nofollow noreferrer">Recoil</a> to manage state in a <a href="https://reactjs.org/" rel="nofollow noreferrer">React</a> application. I am using <a href="https://recoiljs.org/docs/guides/atom-effects/" rel="nofollow noreferrer">Atom Effects</a> to back up recoil values with an API.</p>
  <p>When my Atom detects something wrong with the authentication token I would like it to somehow convey that issue to the rest of the application so that the application can update state.</p>
  <h2>The Details</h2>
  <p>I have several Atoms:</p>
  <ol>
  <li>An atom which stores an authentication token, for use when communicating with the storage API.</li>
  <li>Atoms for various pieces of the application which I would like to save on that storage API.</li>
  </ol>
  <p>In order to perform the API synchronization I have an <code>apiStorageEffect</code> Atom Effect.  The effect uses a recoil-stored authentication token using <code>getPromise</code> and forwards changes using an <code>onSet</code> handler.  That handler uses the token when calling the save method.  The save method can detect when authentication has failed.</p>
  <p>When authentication fails I need to trigger a log out event (setting the token to null, and resetting a series of atoms to their defaults).</p>
  <p>Here is a minimal version of the storage effect:</p>
  <pre class="lang-js prettyprint-override"><code>const apiStorageEffect = (key) =&gt; async ({
      onSet,
      getPromise,
  }) =&gt; {
      const authToken = await getPromise(authTokenAtom)
      if (!authToken) { return }
  
      onSet(async (newValue) =&gt; {
          const result = await saveToApiStorage(key, newValue, authToken)
          if (result.failed) {
              // INSERT CODE TO TRIGGER LOGOUT HERE
          }
      })
  }
  </code></pre>
  <h2>The Question</h2>
  <p>I can think of a few possible paths for triggering logout from within an effect, but all of them involve somehow sending information <em>outside of the affected atom</em> to the main application.</p>
  <ol>
  <li>Is it possible to modify atoms <em>OTHER</em> than the atom / node in question from within an atom effect?</li>
  <li>Is it possible for an atom effect to emit an event that can be immediately handled elsewhere in the React application?</li>
  <li>Is it possible for an atom effect to invoke a method that can modify recoil state more broadly?</li>
  </ol>