|
@@ -1,4 +1,4 @@
|
|
|
-import React from "react";
|
|
|
+import React, { useEffect } from "react";
|
|
|
import {
|
|
|
PRE_GAME,
|
|
|
PRE_ROUND,
|
|
@@ -30,17 +30,19 @@ const paramRouter = {
|
|
|
|
|
|
const Game = () => {
|
|
|
const gameState = useGameState();
|
|
|
-
|
|
|
- const url = new URL(window.location.href);
|
|
|
- for (let [param, value] of url.searchParams.entries()) {
|
|
|
- const route = paramRouter[param];
|
|
|
- if (route) {
|
|
|
- url.searchParams.delete(param);
|
|
|
- window.history.replaceState({}, document.title, url.href);
|
|
|
- route(value);
|
|
|
- break;
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ const url = new URL(window.location.href);
|
|
|
+ for (let [param, value] of url.searchParams.entries()) {
|
|
|
+ const route = paramRouter[param];
|
|
|
+ if (route) {
|
|
|
+ url.searchParams.delete(param);
|
|
|
+ window.history.replaceState({}, document.title, url.href);
|
|
|
+ route(value);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ }, []);
|
|
|
|
|
|
const Screen = componentMap[gameState];
|
|
|
return <Screen />
|