chore: bump version (#2249)
This commit is contained in:
1 parent
1ef408c9ad
commit
496225a92e
16 files changed
+643
-633
No files matched your search
@@ -15,16 +15,16 @@ type SetStateActionWithReset<Value> =
|
||||
// similar to atomWithStorage, but will not trigger twice on init
|
||||
// https://github.com/pmndrs/jotai/discussions/1737
|
||||
export function atomWithSyncStorage<Value>(key: string, initialValue: Value) {
|
||||
const storedValue = storage.getItem(key) as Value;
|
||||
const storedValue = storage.getItem(key, initialValue) as Value;
|
||||
const _value =
|
||||
typeof storedValue === 'symbol'
|
||||
? initialValue
|
||||
: (storage.getItem(key) as Value);
|
||||
: (storage.getItem(key, initialValue) as Value);
|
||||
const baseAtom = atom(_value);
|
||||
|
||||
baseAtom.onMount = setAtom => {
|
||||
if (storage.subscribe) {
|
||||
return storage.subscribe(key, setAtom);
|
||||
return storage.subscribe(key, setAtom, initialValue);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user