Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/BoardSwitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,30 @@ class Board extends React.Component {
}

class BoardSwitcher extends React.Component {
//created a constructor
constructor(props){//error to add super(props)
super(props);
//initialized state to start at index 0
this.state = {
//selectedNum will change based on toggle
selectedNum: 0
};
}

//function to toggle for click
toToggle = () => {
//change state (slectedNum) for index 2 (board 3) to go to index 0 when toggled
this.setState({
selectedNum: this.state.selectedNum < 2 ? this.state.selectedNum + 1 : 0
});
}
render() {
//board array for storing selected
let boards = [];
//for loop for iterating through the max number of boards (3)
for (let ii = 0; ii < this.props.numBoards; ii++) {
let isSelected = ii === 0;
//compares if index i is the 3rd index
let isSelected = ii === this.state.selectedNum;
boards.push(
<Board index={ii} selected={isSelected} key={ii} />
);
Expand All @@ -27,7 +47,7 @@ class BoardSwitcher extends React.Component {
return (
<div>
<div className="boards">{boards}</div>
<button>Toggle</button>
<button onClick={this.toToggle}>Toggle</button>
</div>
);
}
Expand Down