diff --git a/README.md b/README.md index dbe3bde..1c5d401 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/components/BoardSwitcher.jsx b/src/components/BoardSwitcher.jsx index e99793a..e091721 100644 --- a/src/components/BoardSwitcher.jsx +++ b/src/components/BoardSwitcher.jsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; function Board(props) { let className = "board"; @@ -11,15 +11,21 @@ function Board(props) { function BoardSwitcher(props) { let boards = []; + const [currentBoard, setCurrentBoard] = useState(0); + + const toggle = () => { + setCurrentBoard((currentBoard + 1) % props.numBoards); + } + for (let ii = 0; ii < props.numBoards; ii++) { - let isSelected = ii === 0; + let isSelected = ii === currentBoard; boards.push(); } return (
{boards}
- +
); } diff --git a/src/main.jsx b/src/main.jsx index 782f402..316ad56 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -6,6 +6,6 @@ import "./index.css"; const root = ReactDOM.createRoot(document.getElementById("root")); root.render( - + );