Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import './App.scss';
  3. import axios from 'axios';
  4.  
  5. class App extends Component {
  6.  
  7.   // Initital state
  8.   state = {
  9.     cities: null
  10.   }
  11.  
  12.   componentWillMount() {
  13.     const instance = axios.create({
  14.       baseURL: 'https://wft-geo-db.p.mashape.com/v1/geo/cities',
  15.       headers: {'X-Mashape-Key': 'oBb7VvPpYqmshoYOxXbw1E18sQW3p1dAHQyjsnoGwVOTLKs3gd'}
  16.     })
  17.  
  18.     instance.get()
  19.       .then((response) => {
  20.         // We set the state with the cities received from the API
  21.         this.setState({
  22.           cities: response.data
  23.         })
  24.       })
  25.   }
  26.  
  27.   render() {
  28.     const { cities } = this.state
  29.  
  30.     return (
  31.       <div className="app">
  32.         {
  33.           cities ?
  34.             <div className="challenge1">
  35.               <input className="challenge1__searchBar"></input>
  36.             </div>
  37.           :
  38.             <p>Fetching...</p>
  39.         }
  40.       </div>
  41.     );
  42.   }
  43. }
  44.  
  45. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement