super();
                  
                  
                          this.worlds = new Map();
                  
                  
                          this.state={
                  
                  
                            isLoading: true,
                  
                  
                            people: [],
                  
                  
                          }
                  
                  
                      }
                  
                  
                      async componentDidMount()
                  
                  
                      {
                  
                  
                          let self = this;
                  
                  
                         await fetch("https://swapi.co/api/people/?page=1")
                  
                  
                                      .then(function(response){
                  
                  
                                          return response.json();
                  
                  
                                      }).then((response)=>{
                  
                  
                                        this.setState({ people: response.results ,isLoading: false})
                  
                  
                                      })
                  
                  
                                      .catch((error)=>{
                  
                  
                                          console.log(error);
                  
                  
                                      });
                  
                  
                          await this.state.people.map(async (object)=>{
                  
                  
                      
                  
                  
                               await fetch(object.homeworld)
                  
                  
                              .then((response)=> response.json())
                  
                  
                              .then((response)=>{
                  
                  
                                  self.worlds.set(object.name,response.name);
                  
                  
                              })
                  
                  
                          })
                  
                  
                      }
                  
                  
                
Btw fixed this problem.. this thread is closed..
mixing await and then is probably not a good idea. only confuses you a lot more than it should :)
Обсуждают сегодня