Save as empty value, when trying to save undefined var to local storage (#1443)
* Save empty value, when trying to save undefined var to localstorage * Lint fix * Newline at the end of file to satisfy linter? * Linter again
This commit is contained in:
parent
d4ebf69bc7
commit
c9678c5167
1 changed files with 2 additions and 0 deletions
|
@ -9,6 +9,8 @@ export default function useLocalStorage<T>(
|
|||
try {
|
||||
if (typeof valueToStore === "string") {
|
||||
localStorage.setItem(key, valueToStore);
|
||||
} else if (typeof valueToStore === "undefined") {
|
||||
localStorage.setItem(key, "");
|
||||
} else {
|
||||
localStorage.setItem(key, JSON.stringify(valueToStore));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue