Skip to content
Snippets Groups Projects
Commit 2b9445ed authored by Martin Wighus Holtmon's avatar Martin Wighus Holtmon
Browse files

firstpart/Problem4 - Finished - Made a button to switch between the componenets

parent dc5a5b03
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
<title>CS142 Class Project</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script src="modelData/states.js"></script>
<script src="modelData/example.js"></script>
</head>
<body>
<div id="reactapp">
......
import React from 'react';
import ReactDOM from 'react-dom';
import States from './components/states/States';
import Example from './components/example/Example';
//import States from './components/states/States';
class P4 extends React.Component {
constructor(props) {
super(props);
this.handleButtonClick = this.handleButtonClick.bind(this);
this.state = {activePage: States, nextPage: Example}
console.log(this.state.activePage.name)
}
handleButtonClick() {
this.setState({activePage: this.state.nextPage, nextPage: this.state.activePage})
}
render() {
return(
<div>
<button type="button" onClick={this.handleButtonClick}>Switch to {this.state.nextPage.name}</button>
<this.state.activePage/>
</div>
)
}
}
ReactDOM.render(
<h1>page4</h1>,
<P4/>,
document.getElementById('reactapp'),
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment