-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathBoardSwitcher.jsx
More file actions
43 lines (31 loc) · 793 Bytes
/
BoardSwitcher.jsx
File metadata and controls
43 lines (31 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React from "react";
import { useState } from 'react';
function Board(props) {
let className = "board";
if (props.selected) {
className += " selected";
}
return <div className={className}>{props.index + 1}</div>;
}
function BoardSwitcher(props) {
let boards = [];
const [curr, setCurr] = useState(0);
function handleClick() {
if (curr < props.numBoards-1) {
setCurr(curr+1)
} else {
setCurr(0)
}
}
for (let ii = 0; ii < props.numBoards; ii++) {
let isSelected = ii === curr;
boards.push(<Board index={ii} selected={isSelected} key={ii} />);
}
return (
<div>
<div className="boards">{boards}</div>
<button onClick={ handleClick }>Toggle</button>
</div>
);
}
export default BoardSwitcher;