title: Getting items from localstorage returns null
body: <p>I have a React app that loads items from a api call from a database, if there is no data in local storage. I will then set the state with data and load the data in local storage. Next time the app loads it will take the data from local storage instead. The data is mapped out in the return statement.</p>
  
  <p>The Problem is it still returns null even when there is data in local storage.</p>
  
  <p>I will load the data from componentDidMount:</p>
  
  <p>The below code will run the function "loadItems" that first check if there is any data in localstorage (name "workItems") and if so, store it in the state. If it isn't, it will call the database in an api call, store the data to state and also store the data in localstorage which will be used next time the component mounts. I have confirmed that the data is stored in the browser. But when the data from the localstorage exist, is mapped to the state and finally mapped out in the return from the render function it will complain the data is "null". How come? The data is stored in the local storage and exist there when I inspect it from the dev tools. </p>
  
  <pre class="lang-js prettyprint-override"><code>componentDidMount() {
    this.loadItems(false);
  }
  
  async loadItems(forcedUpdate) {
    const payload = {
      forcedUpdate: forcedUpdate
    };
    if (localStorage.getItem('workItems').length &gt; 0) {
      let data = localStorage.getItem("workItems");
      this.setState({
        workitems: localStorage.getItem("workItems"),
        loading: false,
        sources: allSources,
        showSources: allSources,
      }, () =&gt; {
        return;
      });
    }
  
    var apiUrl = "api/WorkItem/GetWorkItems";
  
    const response = await Axios.default.post(apiUrl, payload);
    console.log(response);
    var allSources = response.data.items
      .map(item =&gt; item.source)
      .filter((value, index, self) =&gt; self.indexOf(value) === index);
  
    this.setState({
      workitems: response.data.items,
      loading: false,
      sources: allSources,
      showSources: allSources,
      failedScrape: response.data.failedscrape,
      lastUpdated: response.data.lastUpdated
    });
    localStorage.setItem('workItems', response.data.items);
  
  }
  </code></pre>