Created
July 26, 2018 02:08
-
-
Save pkellner/fc43dd4988490a13c79cfbee0ec0b641 to your computer and use it in GitHub Desktop.
/pages/speaker.js
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 Layout from "../src/components/codecamp/common/Layout"; | |
import Speakers from "../src/components/codecamp/speakers/Speakers"; | |
import axios from "axios"; | |
class speakers extends Component { | |
constructor(props) { | |
super(); | |
this.state = { | |
isLoading: false, | |
data: [] | |
}; | |
} | |
static async getInitialProps() { | |
if (process.browser) { // clientside | |
return { | |
data: [...Array(25)].map((_,i)=>({id:i})), | |
isLoading: true | |
}; | |
} else { // serverside | |
const res = await axios.get('http://localhost:4000/rest/speakers'); | |
return { | |
data: res.data, | |
isLoading: false | |
}; | |
} | |
} | |
render() { | |
return ( | |
<Layout> | |
<Speakers speakers={this.props.data} isLoading={this.props.isLoading}/> | |
</Layout> | |
); | |
} | |
} | |
speakers.propTypes = {}; | |
speakers.defaultProps = {}; | |
export default speakers; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment