• Как добавить async/await метод в класс es6?

    @webzepter
    class AwesomeProject extends Component {
      state = {
          movies: []
      };
    
      componentWillMount() {
        setTimeout(updateMovies, 2000);
      }
    
      @autobind
      async updateMovies() {
        const movies = await this.getMoviesFromApi();
        this.setState({...this.state, movies});
      }
    
      async getMoviesFromApi() {
        const response = await fetch('http://facebook.github.io/react-native/movies.json');
        const responseJson = await response.json();
        return responseJson.movies;
      }
    
      render() {
         return this.state.movies.map(movie => <Movie name={movie.name}/>);
      }
    }
    Ответ написан
    Комментировать