Every Time i try to refresh the page it returns to 0. I'm taking the bestScore from turns when the match is equal to 6, so basically everytime the matched cards hit 6 it will take the bestScore from the turns and save the bestScore to localStoarge and it works but when i try to refresh its gone
function App() {
const [cards, setCards] = useState([]);
const [turns, setTurns] = useState(0);
const [match, matchedCards] = useState(0);
const [bestScore, setBestScore] = useState(
localStorage.getItem("highestScoresss")
);
const [choiceOne, setChoiceOne] = useState(null); //Kullanici 1.karta basinca setChoiceOne o karti alacak ve guncelliyecek
const [choiceTwo, setChoiceTwo] = useState(null); //Kullanici 2.karta basinca setChoiceTwo o karti alacak ve guncelliyecek
const [disabled, setDisabled] = useState(false);
useEffect(() => {
if (match === 6) {
const highScore = Math.min(turns, bestScore);
setBestScore(highScore);
setBestScore(turns);
} else {
console.log("false");
}
}, [turns]);
useEffect(() => {
localStorage.setItem("highestScoresss", JSON.stringify(bestScore));
});
This Is the JSX
<div className="bilgi">
<p>Sıra: {turns}</p>
<p>Bulunan: {match}</p>
<p>En iyi Skor: {bestScore}</p>
<button onClick={shuffleCards}>Yeni Oyun</button>
</div>
</div>