Skip to content

Instantly share code, notes, and snippets.

@syamjayaraj
Created January 25, 2021 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syamjayaraj/695474f0927674f194ddfea5cfe87835 to your computer and use it in GitHub Desktop.
Save syamjayaraj/695474f0927674f194ddfea5cfe87835 to your computer and use it in GitHub Desktop.
import React, { useEffect, useState } from "react";
import { Container, Row, Col } from "react-bootstrap";
import VotingCard from "./components/VotingCard";
import teamsJson from "./lib/teams.json";
import "./assets/scss/styles.scss";
import "bootstrap/dist/css/bootstrap.css";
function App() {
let [teams, setTeams] = useState([]);
useEffect(() => {
setTeams(teamsJson);
}, []);
function incrementVoteCount(teamId) {
teams = teams.map((team) => {
if (team._id === teamId) {
team.votes = team.votes + 1;
}
return team;
});
setTeams(teams);
}
return (
<Container className="app">
<Row>
{teams.map((team) => {
return (
<Col md={4}>
<VotingCard
team={team}
incrementVoteCount={(teamId) => incrementVoteCount(teamId)}
/>
</Col>
);
})}
</Row>
</Container>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment