From 40fe9e3bfac01d754435d3fc8b9f0738504df759 Mon Sep 17 00:00:00 2001 From: prathoseraaj Date: Fri, 3 Oct 2025 14:48:17 +0530 Subject: [PATCH] fix: copilot issues --- memory-game/components/MemoryGame.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/memory-game/components/MemoryGame.jsx b/memory-game/components/MemoryGame.jsx index 709de6e5..effce695 100644 --- a/memory-game/components/MemoryGame.jsx +++ b/memory-game/components/MemoryGame.jsx @@ -1,6 +1,6 @@ "use client"; -import React, { useEffect, useState } from "react"; +import React, { useEffect, useState, useCallback } from "react"; // Fisher-Yates shuffle for unbiased randomization function fisherYatesShuffle(array) { @@ -29,7 +29,7 @@ const MemoryGame = () => { } }; - const initializeGame = () => { + const initializeGame = useCallback(() => { const totalCards = gridSize * gridSize; const pairCount = Math.floor(totalCards / 2); @@ -46,7 +46,11 @@ const MemoryGame = () => { setSelectedPairs([]); setDisabled(false); setWon(false); - }; + }, [gridSize]); + + useEffect(() => { + initializeGame(); + }, [initializeGame]); const handleMatch = (secondId) => { const [firstId] = flipped; @@ -63,10 +67,6 @@ const MemoryGame = () => { } }; - useEffect(() => { - initializeGame(); - }, [gridSize]); - const handleClick = (id) => { if (disabled || won) return;