So I'm trying to build a blackjack game in React. And I'm having trouble figuring out how to update the player and dealer hands when the page reloads or the player asks to take a hit. I've been experimenting with the useEffect hook but my IDE complains about the dealer and player hands being dependencies.
import React, {useEffect, useState} from 'react';
import shuffle from './components/functions/shuffle';
import deck from "./components/deck";
import CurrentPlayer from "./components/CurrentPlayer";
import dealCards from "./components/functions/dealCards";
import Cards from "./components/Cards";
function App() {
document.body.classList.add('bg-secondary', 'text-white');
let dealHandArr: Cards[] = [];
let plaHandArr: Cards[] = [];
const [dealerHand, setDealerHand] = useState<Array<Cards>>();
const [playerHand, setPlayerHand] = useState<Array<Cards>>();
useEffect(() => {
shuffle(deck);
setDealerHand(dealHandArr);
setPlayerHand(plaHandArr);
}, [dealHandArr, dealerHand, plaHandArr, playerHand]);
return (
<div className={'container'}>
<CurrentPlayer hand={playerHand} />
</div>
);
}
export default App;