The purpose of this library is to offer you premade components for showing a football world cup score board.
- We're using
id
as an alternative to a game start time (we assume that a game with a lowerid
started before a game with a higherid
) - As we're using Typescript, we're not validating for the correct input, and the library has shortcomings if used inside a JS project.
- We're assuming that we don't get a list of games with a duplicated
id
npm run dev
will start a dev server with the Example.tsx
showing a usecase for useLiveGames
custom hook. Once
running you can check http://localhost:5173/
in your browser.
The library is made out of 3 parts.
A basic visual component that displays the team names and their respective scores.
const game: Game = {id: 1, home: 'Home team', away: 'Away team', score: {homeScore: 0, awayScore: 1}};
<GameScore game={game} />
A basic visual component that displays a table of game scores.
const games: Game[] = [
{id: 1, home: 'Home team 1', away: 'Away team 1', score: {homeScore: 0, awayScore: 1}},
{id: 2, home: 'Home team 2', away: 'Away team 2', score: {homeScore: 2, awayScore: 1}},
];
<GameScoreTable games={games}/>
A custom React hook that allows you to manage your live games. Check Example.tsx
for a simple use case for useLiveGames
and GameScoreTable
.
const [games, {addGame, finishGame, updateGame}] = useLiveGames();
This method allows you to add new games.
const [games, {addGame, finishGame, updateGame}] = useLiveGames();
addGame({id: 1, home: 'Home team 1', away: 'Away team 1', score: {homeScore: 0, awayScore: 1}});
This method allows you to update the score of an existing game.
const [games, {addGame, finishGame, updateGame}] = useLiveGames();
// id, score
updateGame(1, {homeScore: 0, awayScore: 1}});
This method allows you to finish an existing game.
const [games, {addGame, finishGame, updateGame}] = useLiveGames();
// id
finishGame(1);
npm run build
will create the dist
folder for the library.
npm run test
for running the test suite while watching for file changes.
npm run coverage
for running the tests with code coverage.