Created
November 26, 2020 07:01
-
-
Save zamfi/b7d297569579c4f11e9d95f8df543ae8 to your computer and use it in GitHub Desktop.
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 "./styles.css"; | |
class StartPage extends Component { | |
render() { | |
return <div> | |
<p>Welcome, traveler! How would you like to get to your destination?</p> | |
<button onClick={() => this.props.goToPage(TrainPage)}>Train</button> | |
<button onClick={() => this.props.goToPage()}>Ship</button> | |
</div> | |
} | |
} | |
class TrainPage extends Component { | |
render() { | |
return <div> | |
<p>Welcome aboard the choo-choo train! Please make your way to your seat. What's the number?</p> | |
<button onClick={() => this.props.goToPage()}>12E</button> | |
<button onClick={() => this.props.goToPage()}>97C</button> | |
</div> | |
} | |
} | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
page: StartPage | |
}; | |
} | |
goToPage(pageClass) { | |
if (pageClass) { | |
this.setState({ | |
page: pageClass | |
}); | |
} | |
} | |
render() { | |
let props = { | |
goToPage: (page) => this.goToPage(page), | |
} | |
return <div className="App"> | |
<this.state.page {...props} /> | |
</div> | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment