Advertisement
Xzahn

Main.JS New

Oct 30th, 2018
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react'
  2. import MapContainer from './MapContainer'
  3. import { getTest, getAll } from '../js/StationsAPI'
  4.  
  5. class Main extends Component {
  6.     constructor() {
  7.         super()
  8.         this.state = {
  9.             stations: []
  10.         }
  11.     }
  12.  
  13.     componentDidMount() {
  14.         this.getAllStations()
  15.     }
  16.  
  17.     getAllStations() {
  18.         let getAllPromise = new Promise(resolve => {
  19.             resolve(
  20.                 getAll()
  21.             )
  22.         })
  23.  
  24.         const asyncGet = async () => {
  25.             try{
  26.                 const stations = await getAllPromise.then(stations => stations)
  27.                 this.setState({ stations })
  28.             } catch (e) {}
  29.         }
  30.  
  31.         asyncGet()
  32.     }
  33.  
  34.     render() {
  35.         return <MapContainer stations={this.state.stations}/>
  36.     }
  37. }
  38.  
  39. export default Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement