diff --git a/src/App.js b/src/App.js index 6e5fff5..c5f73df 100644 --- a/src/App.js +++ b/src/App.js @@ -6,6 +6,7 @@ import PuzzleWord from "./components/Hangman/PuzzleWord/PuzzleWord"; import Victory from "./components/Hangman/PuzzleWord/Victory"; import Defeat from "./components/Hangman/PuzzleWord/Defeat"; import Loading from "./components/Loading"; +import AlmacenateCurrentScore from "./components/Scripts/AlmacenateCurrentScore"; function App() { @@ -19,10 +20,22 @@ function App() { const [displayApp, setDisplayApp] = useState(false) + React.useEffect(() => { + + if (localStorage.getItem('currentScore')) { + + setCurrentScore(localStorage.getItem('currentScore')) + localStorage.removeItem('currentScore') + } + + }) + if (isVictory || isDefeat) { setTimeout(() => { + AlmacenateCurrentScore(currentScore) + window.location.reload(true); }, 3000) } diff --git a/src/components/Hangman/PuzzleWord/Victory.jsx b/src/components/Hangman/PuzzleWord/Victory.jsx index 5fa9c1a..b25165f 100644 --- a/src/components/Hangman/PuzzleWord/Victory.jsx +++ b/src/components/Hangman/PuzzleWord/Victory.jsx @@ -4,7 +4,8 @@ const Victory = ({currentScore, setCurrentScore}) => { React.useEffect(() => { - setCurrentScore(currentScore + 1) + setCurrentScore(parseInt(currentScore) + 1) + }, []) return ( diff --git a/src/components/Scripts/AlmacenateCurrentScore.js b/src/components/Scripts/AlmacenateCurrentScore.js new file mode 100644 index 0000000..13c47c1 --- /dev/null +++ b/src/components/Scripts/AlmacenateCurrentScore.js @@ -0,0 +1,6 @@ +const AlmacenateCurrentScore = (currentScore) => { + + localStorage.setItem('currentScore', currentScore) +} + +export default AlmacenateCurrentScore