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
localStorageand reset them after 10mins. - I set
correctWordas 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
0and then restart the count down process again. - I tried to save the
timeLeftuntil the correct word is changed into thelocalStoragebut it would just stay at0and 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
localStoragebecause 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