From 8ea52c5e375369984ae0f06948f80d6b83ba949b Mon Sep 17 00:00:00 2001 From: Matin Nazamy Date: Fri, 1 Oct 2021 12:08:08 -0400 Subject: [PATCH] Updated toggle button feature --- src/BoardSwitcher.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/BoardSwitcher.js b/src/BoardSwitcher.js index 61ad96f..a8daba2 100644 --- a/src/BoardSwitcher.js +++ b/src/BoardSwitcher.js @@ -15,19 +15,32 @@ class Board extends React.Component { } class BoardSwitcher extends React.Component { + constructor(props){ + super(props); + this.state = { + spot: 0, + }; + } + + handleClick(event){ + this.setState({ + spot: (this.state.spot+1)%3 + }) + } + render() { - let boards = []; - for (let ii = 0; ii < this.props.numBoards; ii++) { - let isSelected = ii === 0; + let boards = []; // empty array of boards + for (let ii = 0; ii < this.props.numBoards; ii++) { // fill the array with n(param) boards + let isSelected = ii === this.state.spot; // let the first one be selected boards.push( - + // returns a 'Board' object with those params ); } return (
{boards}
- +
); }