Can not use keyword 'await' outside an async function in a custom React hook : <p>I'm trying to create a custom hook, but I keep getting the error for the <code>getToken()</code> function: </p>

<blockquote>
  <p>Can not use keyword 'await' outside an async function</p>
</blockquote>

<p>How do I get around this issue?</p>

<pre class="lang-js prettyprint-override"><code>export const useExistingToken = async () =&gt; {
    const [existingToken, setExistingToken] = useState('')
    const [tokenLocallyExists, tokenLocalCheck] = useState()
    useEffect(() =&gt; {
        if (!tokenLocallyExists) {
            const token = await getToken() // issue here
            setExistingToken(token)
        }
    }, [])

    return [existingToken, tokenLocalCheck]
}
</code></pre>
