Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

PP lab react toggle - Edgardo Molina (Prof) and Akbar Mirza (TA) - Friday OSL 3pm #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
13 changes: 9 additions & 4 deletions src/components/BoardSwitcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import React, {useState} from "react";

let currentState=1;
function Board(props) {
let className = "board";
if (props.selected) {
Expand All @@ -10,18 +11,22 @@ function Board(props) {
}

function BoardSwitcher(props) {
const [currentState, setCurrentState] = useState(0);

const onClickToggle=() =>{
setCurrentState((prevState)=>(prevState+1)%5);
}
let boards = [];
for (let ii = 0; ii < props.numBoards; ii++) {
let isSelected = ii === 0;
let isSelected = ii === currentState;
boards.push(<Board index={ii} selected={isSelected} key={ii} />);
}

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

export default BoardSwitcher;
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>
);