title: waiting forEach to finish using setState in react
body: <p>How do I wait for setState in a foreach to finish then show the render?</p>
  
  <pre><code>class App extends Component {
    componentDidMount() {
      someArrOfObject.forEach(o =&gt; {
        this.setState({
          [`list_for_${o.id}`]: o.val
        })
      })
    }
  
    render() {
  
      const { selected_id } = this.state
      const selected_list = this.state[`list_for_${selected_id}`]
  
      return selected_list.map(o =&gt; &lt;div&gt;{o.val}&lt;/div&gt;)
    }
  }
  </code></pre>