Skip to content

Commit

Permalink
Removing React Context
Browse files Browse the repository at this point in the history
We don't need a React context, its provider, nor the useContext hook.
In our components we switch from consuming "useGamesContext" to "useGames"
  • Loading branch information
JulianG committed Feb 26, 2020
1 parent 4b2f4c5 commit 9a7e8eb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
20 changes: 0 additions & 20 deletions src/GamesContext.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/GameGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { GameComponent } from './GameComponent';
import { useGamesContext } from '../GamesContext';
import { useGames } from '../useGames';

export const GameGrid = () => {
const { games, error, isPending, markAsFinished } = useGamesContext();
const { games, error, isPending, markAsFinished } = useGames();

return (
<div className="gamegrid">
Expand Down
5 changes: 2 additions & 3 deletions src/components/GamesScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react';
import { Totals } from './Totals';
import { GameGrid } from './GameGrid';
import { GamesContextProvider } from '../GamesContext';

export const GamesScreen = () => {
return (
<GamesContextProvider>
<>
<Totals />
<GameGrid />
</GamesContextProvider>
</>
);
};
4 changes: 2 additions & 2 deletions src/components/Totals.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { useGamesContext } from '../GamesContext';
import { useGames } from '../useGames';

export const Totals = () => {
const { games } = useGamesContext();
const { games } = useGames();

const totalGames = games.length;
const inProgress = games.filter(g => g.status === 'in-progress').length;
Expand Down

0 comments on commit 9a7e8eb

Please sign in to comment.