Skip to content

Instantly share code, notes, and snippets.

@zamfi
Created November 26, 2020 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zamfi/b7d297569579c4f11e9d95f8df543ae8 to your computer and use it in GitHub Desktop.
Save zamfi/b7d297569579c4f11e9d95f8df543ae8 to your computer and use it in GitHub Desktop.
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