Created
March 8, 2019 19:05
-
-
Save juulhao/f42a80fd8c28575152ae3bcd92184826 to your computer and use it in GitHub Desktop.
refresh fetch and caching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import logo from './assets/images/logo.svg'; | |
import './App.css'; | |
import { Fetch } from 'react-data-fetching' | |
import api from './utils/api'; | |
import CardClima from './components/CardClima'; | |
class App extends Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
loading: false, | |
cidades: [] | |
} | |
} | |
refreshData() { | |
} | |
componentDidMount() { | |
this.setState({ loading: true }, () => { | |
api.getNairobi().then(response => { | |
this.setState({ | |
loading: false, | |
cidades: [...this.state.cidades, response]} | |
) | |
}) | |
api.getUbirici().then(response => { | |
this.setState({ | |
loading: false, | |
cidades: [...this.state.cidades, response]} | |
) | |
}) | |
api.getNuuk().then(response => { | |
this.setState({ | |
loading: false, | |
cidades: [...this.state.cidades, response]} | |
) | |
}) | |
}); | |
setInterval(() => this.setState({ | |
// logica aqui | |
}), 1000); | |
} | |
render() { | |
const {loading, cidades} = this.state | |
return ( | |
<div className="App"> | |
{ | |
loading ? <Loading/> : | |
cidades.map((cidades, i) => | |
<CardClima | |
key={i} | |
local={cidades.name} | |
temperatura={cidades.main.temp} | |
humidity={cidades.main.humidity} | |
pressure={cidades.main.pressure} | |
horaAtualizacao={new Date().toLocaleTimeString()} | |
card_name={cidades.name} | |
/> | |
) | |
} | |
</div> | |
); | |
} | |
} | |
const Loading = () => <img src={require('./assets/images/loader.svg')} alt="Carregando dados" />; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment