refactor: Refactor CounterCard component to use BigInt for globalCount

Refactor CounterCard component to use BigInt for globalCount state and parse globalCount as an integer
This commit is contained in:
Ayane Satomi 2023-10-22 05:50:37 +00:00
parent 6b05b7d6a9
commit f2abd5110c

View file

@ -45,7 +45,9 @@ export function animateMascot() {
export default function Counter(props: SharedProps) { export default function Counter(props: SharedProps) {
const [count, setCount] = useState(0); const [count, setCount] = useState(0);
const [globalCount, setGlobalCount] = useState(props.globalCount ?? 0); const [globalCount, setGlobalCount] = useState(
BigInt(props.globalCount ?? 0),
);
const [internalCount, setInternalCount] = useState(0); const [internalCount, setInternalCount] = useState(0);
const [timer, setTimer] = useState(0); const [timer, setTimer] = useState(0);
@ -104,7 +106,7 @@ export default function Counter(props: SharedProps) {
es.addEventListener("message", (e) => { es.addEventListener("message", (e) => {
console.log(`[${new Date()}] Received global count: ${e.data}`); console.log(`[${new Date()}] Received global count: ${e.data}`);
const data = JSON.parse(e.data); const data = JSON.parse(e.data);
setGlobalCount(parseInt(data.globalCount)); setGlobalCount(BigInt(parseInt(data.globalCount)));
}); });
// TODO: Reconnect backoff logic could be improved // TODO: Reconnect backoff logic could be improved