title: React Native - Fetch data from API with Authorization Bearer Token
body: <p>I am trying to fetch data of user profile and I got this error</p>
  <p>&quot;Unexpected token U in JSON at position 0&quot; in my Android Simulator</p>
  <p>I checked with in my console.log and I manage to get my API properly so I think that is not the issue</p>
  <p>This is my Home index.js (the file trying to fetch data)</p>
  <pre><code>import AsyncStorage from '@react-native-async-storage/async-storage';
  import React, {useEffect, useState} from 'react';
  import {StyleSheet, Text, View} from 'react-native';
  import {getData} from '../../utils';
  
  export default function Home() {
    const [data, setData] = useState([]);
    const [token, setToken] = useState('');
    useEffect(() =&gt; {
      getData('token').then(res =&gt; {
        const res_token = res;
        console.log('token response: ', res_token);
        setToken(res_token);
      });
    }, []);
  
    useEffect(() =&gt; {
      fetch('https://emaillead.aturtoko.id/api/v1/profile', {
        method: 'GET',
        headers: {
          Accept: 'application/json',
          'Content-Type': 'application/json',
          Authorization: token,
        },
      })
        .then(response =&gt; response.json())
        .then(json =&gt; {
          console.log('token auth: ' + token);
          setData(json);
          console.log(json);
        })
        .catch(error =&gt; console.error(error));
    }, [token]);
    return (
      &lt;View&gt;
        &lt;Text&gt;Nama: {data.name}&lt;/Text&gt;
      &lt;/View&gt;
    );
  }
  
  const styles = StyleSheet.create({});
  </code></pre>
  <p>So I got the token from my login page. I tried to make 2 useEffect, one to get the token and the other to get the data from API. I also tried the only 1 useEffect before as well with the same result.</p>
  <p>This is the code when I use only 1 useEffect</p>
  <pre><code>useEffect(() =&gt; {
      getData('token').then(res =&gt; {
        const res_token = res;
        console.log('token response: ', res_token);
        setToken(res_token);
      });
      fetch('https://emaillead.aturtoko.id/api/v1/profile', {
        method: 'GET',
        headers: {
          Accept: 'application/json',
          'Content-Type': 'application/json',
          Authorization: token,
        },
      })
        .then(response =&gt; response.json())
        .then(json =&gt; {
          console.log('token auth: ' + token);
          setData(json);
          console.log(json);
        })
        .catch(error =&gt; console.error(error));
    }, [token]);
  </code></pre>
  <p>I don't know where is the problem with my code right now</p>