I'm curious about the saving and retrieving from localStorage in Wordle and how is it implemented in React.
I'm building a Wordle clone as a project but I'm having a roadblock at this point. Most of the resources I found wouldn't go into how it works. If anyone ever has success with this thing, please help me out. Thanks a lot :)
In my case, I have a words.json
file containing all the words.
- I want to set a timer so that after 10 minutes, the random correct word will change.
- All the guessed keys, guessed words, the counting timer, and the current correct word are saved in the localStorage so.
- When the correct word is changed, all data in the localStorage above are being reset to the fresh stage. (Yes, also clear out the tiles)
Problems:
- Up to this point, my code can fetch a new word every 10 minutes but I don't know how to save all of the data to the
localStorage
and reset them after 10mins. - I set
correctWord
as an empty string for the initial state, if I type""
into the board, the game will break because it matches the winning condition. (currentWord === correctWord
) - The timer skips the number
0
and then restart the count down process again. - I tried to save the
timeLeft
until the correct word is changed into thelocalStorage
but it would just stay at0
and not doing anything. If i refresh the page, the timer would just start from the start again, not from the point it should be left. - I'm not applying the right code to save in the
localStorage
because I copied some of it. Please feel free to let me know what can I change to fit my code.
All code is embed in this codesandbox below