Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Louiefigz/e6e1af3459c3ecee5c5adbd4ef9b1519 to your computer and use it in GitHub Desktop.
Save Louiefigz/e6e1af3459c3ecee5c5adbd4ef9b1519 to your computer and use it in GitHub Desktop.
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