title: React.js this2.setState is not a function?
body: <p>I am trying to retrieve pokemon data from the pokemon api, my problem is rendering out my state. i get <code>TypeError: _this2.setState is not a function</code> and not sure why. Should i be doing this fetch call outside the componentDidMount function ? i am a newbie to react and am just trying to learn. </p>
  
  <pre><code>import ReactDOM from "react-dom";
  import styled from "styled-components";
  
  import "./styles.css";
  
  class App extends Component {
    state = {
      allPokemon: []
    };
  
    componentDidMount() {
      let images = [];
      async function fetchPokeMonData() {
        const response = await fetch("https://pokeapi.co/api/v2/pokemon");
        const data = await response.json();
        return await Promise.all(
          data.results.map(async pokemon =&gt; {
            const response = await fetch(pokemon.url);
            const pokemonData = await response.json();
  
            console.log(
              pokemonData.id,
              pokemonData.name,
              pokemonData.sprites.front_default
            );
            this.setState({
              allPokemon: {
                id: pokemonData.id,
                name: pokemonData.name,
                sprite: pokemonData.sprites.front_default
              }
            });
  
            return images;
          })
        ).catch(err =&gt; {
          console.error(err);
        });
      }
      fetchPokeMonData();
    }
  
    render() {
      return &lt;StyledApp&gt;{console.log(this.images)}&lt;/StyledApp&gt;;
    }
  }
  
  const StyledApp = styled.div`
    height: 100vh;
  
    background: linear-gradient(
      to right,
      #8e9eab,
      #eef2f3
    ); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
  
    padding: 30px;
  `;
  
  const rootElement = document.getElementById("root");
  ReactDOM.render(&lt;App /&gt;, rootElement);
  
  </code></pre>
  
  <p>i am making this in a codesandbox url here <a href="https://codesandbox.io/s/w6momrq41k" rel="nofollow noreferrer">https://codesandbox.io/s/w6momrq41k</a></p>
  
  <p>Thank you in advance. </p>