I'd wrap this listener on the if, since it won't work if there's no localstorage.