React Native wait for AsyncStorage to get value
<p>Its a common problem, React Native trying to render before the values have been fetched from AsyncStorage. I've seen solutions for this in several places but for some reason it just doesn't work at all for me. Maybe its because I'm using React Native 25.1? It just gets stuck on 'Loading...' indefinitely. If I run a console log on render to show isLoading (without the <code>if</code> method) it returns <code>false</code> and then <code>true</code> so theoretically it should be working. But with the <code>if</code> method enabled its stuck on 'Loading' forever and also the log only returns false.</p>

<pre><code>import React, { Component } from 'react';

import {
  Text,
  View,
  AsyncStorage
} from 'react-native';

  class MainPage extends Component {
   constructor(props: Object): void {
   super();
   this.state = {
     isLoading: false,
   };
 }

  componentWillMount() {
    AsyncStorage.getItem('accessToken').then((token) =&gt; {
      this.setState({
        isLoading: false
      });
    });
  }

  render() {
    if (this.state.isLoading) {
      return &lt;View&gt;&lt;Text&gt;Loading...&lt;/Text&gt;&lt;/View&gt;;
    }
    // this is the content you want to show after the promise has resolved
    return &lt;View/&gt;;
  }

});
</code></pre>