Skip to content
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
15 changes: 10 additions & 5 deletions src/components/BoardSwitcher.jsx
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,18 +10,23 @@ function Board(props) {
}

function BoardSwitcher(props) {
const [selectedBoard, setSelectedBoard] = useState(0);

const toggleBoard = () => {
setSelectedBoard((prevBoard) => (prevBoard + 1) % props.numBoards);
};

let boards = [];
for (let ii = 0; ii < props.numBoards; ii++) {
let isSelected = ii === 0;
let isSelected = ii === selectedBoard;
boards.push(<Board index={ii} selected={isSelected} key={ii} />);
}

return (
<div>
<div className="boards">{boards}</div>
<button>Toggle</button>
<button onClick={toggleBoard}>Toggle</button>
</div>
);
}

export default BoardSwitcher;
export default BoardSwitcher;
6 changes: 5 additions & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import BoardSwitcher from "./components/BoardSwitcher";
import "./index.css";

const root = ReactDOM.createRoot(document.getElementById("root"));

//switch from 3 -> 5 boards
//BoardSwitcher allows for toggle button. if you give it a specific amount it
//will create the boxes
root.render(
<React.StrictMode>
<BoardSwitcher numBoards={3} />
<BoardSwitcher numBoards={5} />
</React.StrictMode>
);