All files / lib/providers/GameScreen index.tsx

33.33% Statements 3/9
100% Branches 0/0
20% Functions 1/5
33.33% Lines 2/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23        1x                 15x                  
import { Game } from '@uniquegood/realworld-web-interface/lib/models/game';
import { Screen } from '@uniquegood/realworld-web-interface/lib/models/game/Screen';
import React, { useContext, createContext } from 'react';
 
const GameScreenContext = createContext<{
  getScreenById: (itemId: string) => Screen | undefined;
}>({
  getScreenById: () => {
    // pass
    return undefined;
  }
});
 
export const useGameScreenContext = () => useContext(GameScreenContext);
 
export function GameScreenProvider({ children, game }: { children: React.ReactNode; game: Game }) {
  const getScreenById = React.useCallback((screenId: string) => game.screenMap[screenId], [game]);
 
  const value = React.useMemo(() => ({ getScreenById }), [getScreenById]);
 
  return <GameScreenContext.Provider value={value}>{children}</GameScreenContext.Provider>;
}