fix: copilot issues

pull/1500/head
prathoseraaj 11 months ago
parent 2ec0937ecc
commit 40fe9e3bfa

@ -1,6 +1,6 @@
"use client"; "use client";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState, useCallback } from "react";
// Fisher-Yates shuffle for unbiased randomization // Fisher-Yates shuffle for unbiased randomization
function fisherYatesShuffle(array) { function fisherYatesShuffle(array) {
@ -29,7 +29,7 @@ const MemoryGame = () => {
} }
}; };
const initializeGame = () => { const initializeGame = useCallback(() => {
const totalCards = gridSize * gridSize; const totalCards = gridSize * gridSize;
const pairCount = Math.floor(totalCards / 2); const pairCount = Math.floor(totalCards / 2);
@ -46,7 +46,11 @@ const MemoryGame = () => {
setSelectedPairs([]); setSelectedPairs([]);
setDisabled(false); setDisabled(false);
setWon(false); setWon(false);
}; }, [gridSize]);
useEffect(() => {
initializeGame();
}, [initializeGame]);
const handleMatch = (secondId) => { const handleMatch = (secondId) => {
const [firstId] = flipped; const [firstId] = flipped;
@ -63,10 +67,6 @@ const MemoryGame = () => {
} }
}; };
useEffect(() => {
initializeGame();
}, [gridSize]);
const handleClick = (id) => { const handleClick = (id) => {
if (disabled || won) return; if (disabled || won) return;

Loading…
Cancel
Save