Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ To start off and understand the desired toggle effect, try changing `let isSelec

### Tasks

- [ ] change the app to render 5 boards
- [ ] add state to track current selection
- [ ] add an event handler for the toggle button
- [x] change the app to render 5 boards
- [x] add state to track current selection
- [x] add an event handler for the toggle button

### To submit

Expand Down
13 changes: 10 additions & 3 deletions src/components/BoardSwitcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, {useState} from "react";

function Board(props) {
let className = "board";
Expand All @@ -10,16 +10,23 @@ function Board(props) {
}

function BoardSwitcher(props) {
const [currentIndex, setBoard] = useState(0);
let boards = [];

const handleClick = (event) => {
setBoard((currentIndex + 1) % props.numBoards);
};

for (let ii = 0; ii < props.numBoards; ii++) {
let isSelected = ii === 0;
let isSelected = ii === currentIndex;

boards.push(<Board index={ii} selected={isSelected} key={ii} />);
}

return (
<div>
<div className="boards">{boards}</div>
<button>Toggle</button>
<button onClick = {handleClick}>Toggle</button>
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import "./index.css";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<BoardSwitcher numBoards={3} />
<BoardSwitcher numBoards={5} />
</React.StrictMode>
);