Game Data Access Example

This page demonstrates how to access game data from anywhere in the application using our global context.

Controls

Leave empty to see all games for the selected sport

Back to Home

Game Data Access

Usage Example

// Access game data anywhere in your app
import { useGameData } from '@/context/GameDataContext';

function YourComponent() {
  const { getGame, getGamesBySport, games, isLoading } = useGameData();
  
  // For a specific game
  useEffect(() => {
    async function loadGameData() {
      const game = await getGame('baseball_mlb', 'game-id-here');
      // Use game data...
    }
    loadGameData();
  }, []);
  
  // OR directly access from cache if already loaded
  const cachedGame = games['game-id-here'];
  
  // For all games in a sport
  useEffect(() => {
    async function loadSportGames() {
      const games = await getGamesBySport('baseball_mlb');
      // Use games data...
    }
    loadSportGames();
  }, []);
}