Relative Content

Tag Archive for javascriptreactjsreact-hookslocal-storagemaps

React: Reading map from local storage returns null values

I am making a small game website where users choose between “easy, medium, and hard” difficulties and I am using a hook of type map to keep track of the guess count for each difficulty. I got it to work normally, but the problem is I want to save user’s guesses so if they come back the website will remember where they were at in the game similar to games like Wordle. However, the code below returns undefined if localstorage is empty when it should be returning 6 as shown below.