Last active
June 24, 2019 18:34
-
-
Save ghardin137/cfb3d49843f82324589ecda37573dbe4 to your computer and use it in GitHub Desktop.
REACT SAMPLE
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 axios from 'axios'; | |
export function getData(_url){ | |
return axios.get(`${_url}?v=${_now}`) | |
.catch(error => { | |
console.log(error); | |
}); | |
}; |
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 ReactDOM from 'react-dom'; | |
import Banner from './stateless/Banner/Banner'; | |
import ContestWinnerList from './stateless/ContestWinnerList/ContestWinnerList'; | |
import { getData, closeRequest } from './helpers/GetDailyContestWinners'; | |
class DailyContestWinners extends Component { | |
state = { | |
externalData: [], | |
loading: false, | |
} | |
mounted = false; | |
componentDidMount() { | |
console.log("DailyContestWinners Component Mounted..."); | |
this.setState({ loading: true }); | |
this.mounted = true; | |
// Make API request, passing this as a param to setState with exteranlData loaded... | |
getData('https://cdn.lucktastic.com/images/daily-winners/winners.json').then(response => { | |
if(this.mounted) this.setState({externalData: response.data, loading: false}); | |
}); | |
} | |
componentWillUnmount() { | |
this.mounted = false; | |
} | |
render() { | |
console.log("Updated state with payload. Ready to pass and render."); | |
return( | |
<div className={"view-wrapper"}> | |
<Banner/> | |
{ !this.state.loading && this.state.externalData.length > 0 && <ContestWinnerList data={this.state.externalData}/> } | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment