|
@@ -5,15 +5,15 @@ import { useGameId } from '../domain/gameStore';
|
|
|
|
|
|
export default () => {
|
|
|
const gameId = useGameId();
|
|
|
- const [scores, setScores] = useState(null);
|
|
|
+ const [info, setInfo] = useState({ players: null });
|
|
|
|
|
|
useEffect(() => {
|
|
|
// define how to fetch scores
|
|
|
const fetchInfo = async () => {
|
|
|
- const { players } = await gameInfo(gameId);
|
|
|
- // TODO maybe have back-end provide timestamp? to avoid this check
|
|
|
- if (!dequal(players, scores)) {
|
|
|
- setScores(players);
|
|
|
+ const newInfo = await gameInfo(gameId);
|
|
|
+ // TODO maybe have back-end provide timestamp? to avoid this check
|
|
|
+ if (!dequal(info, newInfo)) {
|
|
|
+ setInfo(newInfo);
|
|
|
}
|
|
|
};
|
|
|
// when the hook triggers, fetch the game info
|
|
@@ -22,7 +22,7 @@ export default () => {
|
|
|
const interval = setInterval(() => fetchInfo(), 5000);
|
|
|
// and return a clean-up callback
|
|
|
return () => { clearInterval(interval) };
|
|
|
- }, [gameId, scores]);
|
|
|
+ }, [gameId, info]);
|
|
|
|
|
|
- return scores;
|
|
|
+ return info;
|
|
|
}
|