Skip to content

Commit f63f14f

Browse files
committed
docs(changeset): fix: default to new value if not cached
1 parent 39a5924 commit f63f14f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

.changeset/ripe-hands-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"kosha": patch
3+
---
4+
5+
fix: default to new value if not cached

lib/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const create = <T extends BaseType>(storeCreator: StoreCreator<T>) => {
5555
const useHook = <U = T>(selectorFunc?: (state: T) => U): U => {
5656
const getSlice = () => {
5757
const newValue = selectorFunc!(get()!);
58-
const obj = map.get(selectorFunc!);
58+
const obj = map.get(selectorFunc!) ?? newValue;
5959
const finalValue = JSON.stringify(obj) === JSON.stringify(newValue) ? obj : newValue;
6060
map.set(selectorFunc!, finalValue);
6161
return finalValue as U;

0 commit comments

Comments
 (0)