I am creating a memory game, i have a shuffle function that shuffles an array of numbers, these numbers are rendered as cards, the problem is that the cards are shuffled every time state changed, i need to only initialize my component with a shuffled array that persists even state is changed!
i tried useEffect, but it doesn't work, or i couldn't implement it correctly
code:
const numbers = [1, 2, 3, 1, 2, 3];
const shuffle = (arr) => {
//shuffle logic here
}
let shuffledCards;
useEffect(() => {
shuffledCards = shuffle(numbers) // it doesn't help
}, [])
return(
<cards shuffledCards={shuffledCards} />
)
how can i shuffle my array once instead of every time state is changed!