Skip to content

Commit

Permalink
fix(utils): atomWithStorage to always run onMount
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Mar 15, 2024
1 parent 9952649 commit ba4e4e3
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/vanilla/utils/atomWithStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ export function atomWithStorage<Value>(
}

baseAtom.onMount = (setAtom) => {
if (!getOnInit) {
setAtom(storage.getItem(key, initialValue) as Value | Promise<Value>)
}
setAtom(storage.getItem(key, initialValue) as Value | Promise<Value>)
let unsub: Unsubscribe | undefined
if (storage.subscribe) {
unsub = storage.subscribe(key, setAtom, initialValue)
Expand Down

0 comments on commit ba4e4e3

Please sign in to comment.