Skip to content

Commit

Permalink
adjust after comments on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Flirre committed Feb 27, 2024
1 parent 1491143 commit 80c21f9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/atomWithHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export function atomWithHash<Value>(
},
): WritableAtom<Value, [SetStateActionWithReset<Value>], void> {
const serialize = options?.serialize || JSON.stringify;
let hashValueInURL;
if (global.window) {
hashValueInURL = new URLSearchParams(window.location.hash.slice(1)).get(
let initialValueInHash: string | null = null;
if (typeof window !== 'undefined') {
initialValueInHash = new URLSearchParams(window.location.hash.slice(1)).get(
key,
);
}
Expand Down Expand Up @@ -57,7 +57,7 @@ export function atomWithHash<Value>(
if (typeof setHashOption === 'function') {
setHash = setHashOption;
}
const strAtom = atom<string | null>(hashValueInURL ?? null);
const strAtom = atom(initialValueInHash);
strAtom.onMount = (setAtom) => {
if (typeof window === 'undefined' || !window.location) {
return undefined;
Expand Down

0 comments on commit 80c21f9

Please sign in to comment.