title: How to assign value to global variable in fetch method in react native?
body: <p>I am creating a react native app and I'm getting data from an API. I need to assign specific data into a global variable. That means my API return JSON data like {user_Id:"1' user_name:'abc' user_email:'abc@gmail.con'}. I need to assign user_Id into a global variable to access that in all of my screens. </p>
  
  <p><strong>This is what I tried;</strong></p>
  
  <pre><code>componentDidMount() {
      const arrFinal = [];
      const {userDel} = this.state;
      fetch('my API url')
        .then(response =&gt; response.json())
        .then(responseJson =&gt; {
          // console.warn(responseJson);
          arrFinal.push(responseJson);
          arrFinal.map((item, index) =&gt; {
           global.UserID = item.user_Id
        })
        .catch(error =&gt; {
          console.error(error);
        });
     console.error(global.UserID)
    }
  </code></pre>
  
  <p>But here nothing will print on console. How can I fix this problem?</p>