title: Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'error')
body: <pre><code>const getToken = (userId, token) =&gt; {
    22 |   getmeToken(userId, token).then((info) =&gt; {
    23 |     console.log(&quot;INFO COMING&quot;, info);
  &gt; 24 |     if (info.error) {
    25 |      setInfo({ ...info, error: info.error });
    26 |     } else {
    27 |       const clientToken = info.clientToken;
  
  </code></pre>
  <p>What is meant by Unhandled rejection, cannot read properties of undefined??.</p>
  <p>I have defined the <strong>error</strong> and also assigned a value for it, below is the code of <code>useState</code></p>
  <pre><code>  const [info, setInfo] = useState({
      loading: false,
      success: false,
      clientToken: null,
      error:&quot;&quot;,
      instance: {},
    });
  </code></pre>
  <p>As per the above code, I have defined and assigned the value for error, then why is the browser still showing <strong>cannot read properties of undefined</strong>.
  Can anyone please clarify this?</p>
  <p><strong>getmeToken</strong> function code is below</p>
  <pre><code>export const getmeToken = (userId, token) =&gt; {
      return fetch(` ${API}/payent/gettoken/${userId}`, {
          method: &quot;GET&quot;,
          headers: {
              Accept: &quot;application/json&quot;,
              &quot;Content-Type&quot;: &quot;application/json&quot;,
              Authorization: `Bearer ${token}`
          }
      }).then(response =&gt; {
          return response.json();
      })
      .catch(err =&gt; console.log(err))
  }
  </code></pre>