Created
May 13, 2017 20:23
-
-
Save Louiefigz/e6e1af3459c3ecee5c5adbd4ef9b1519 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 WeatherFetcher from '../utils/WeatherFetcher'; | |
class Forecast extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
loaded: false | |
} | |
} | |
// remember that the below function only runs once; | |
// when the page renders to the DOM. | |
componentDidMount() { | |
WeatherFetcher.fetchFiveDayWeather(this.props.routeParams.city) | |
.then((data) => this.setState({fiveDayWeather: data.data, loaded: true})); | |
} | |
//while you're on this component and any new city is called | |
// in your navbar, the function below will run. This funciton | |
// is constantly looking for any new props that are being sent | |
// to this component. | |
componentWillReceiveProps(nextProps) { | |
WeatherFetcher.fetchFiveDayWeather(nextProps.routeParams.city) | |
.then((data) => this.setState({fiveDayWeather: data.data, loaded: true})); | |
} | |
render(){ | |
return( | |
<div> | |
<h1>yooooo</h1> | |
</div> | |
) | |
} | |
} | |
export default Forecast; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment