Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ const useLocalStorage = <T>(
if (!isBrowser) {
return [initialValue as T, noop, noop];
}

if (!key) {
throw new Error('useLocalStorage key may not be falsy');
}

const deserializer = options
? options.raw
? (value) => value
? (value: string) => value
: options.deserializer
: JSON.parse;

Expand Down Expand Up @@ -79,7 +80,8 @@ const useLocalStorage = <T>(
// localStorage can throw. Also JSON.stringify can throw.
}
},
[key, setState]
// eslint-disable-next-line react-hooks/exhaustive-deps
[key, setState, state]
);

// eslint-disable-next-line react-hooks/rules-of-hooks
Expand Down