import React, {useState, useRef, useLayoutEffect} from 'react'; import twemoji from 'twemoji'; import ReactRouter from 'react-router'; import {GameState, useListener} from './GamesUtil'; import './GamePage.css'; import Game from './Game'; import {getUID} from './util'; function GamePage(props: ReactRouter.RouteComponentProps<{id: string}>) { let [game, setGame] = useState<[string, GameState]|undefined>(undefined); let history = useRef<[number, string, string][]>([]); useListener((newGames) => { let newGame = newGames.find((gamePair) => gamePair[0] === props.match.params.id); setGame(newGame); console.log(newGame); if (newGame !== undefined && newGame[1].start_delay < 0 && newGame[1].end_delay > 8) { history.current.unshift([getUID(), newGame[1].update_emoji, newGame[1].update_text]); if (history.current.length > 8) { history.current.pop(); } } }); if (game === undefined) { return