Skip to content

Commit ae2c645

Browse files
committed
chore(core/useObservable): improve implementation
1 parent eacde15 commit ae2c645

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

packages/core/src/internal/useObservable.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,18 @@ export const useObservable = <O>(
3434
}, onError)
3535
if (err !== EMPTY_VALUE) return
3636

37-
const set = (value: O | (() => O)) => {
37+
const set = (value: O) => {
3838
if (!Object.is(prevStateRef.current, value)) {
39-
prevStateRef.current = value
40-
if (typeof value === "function") {
41-
setState(() => [(value as any)(), source$])
42-
} else {
43-
setState([value, source$])
44-
}
39+
setState([(prevStateRef.current = value), source$])
4540
}
4641
}
4742

48-
if (syncVal === EMPTY_VALUE) {
49-
set(defaultValue)
50-
}
43+
if (syncVal === EMPTY_VALUE) set(defaultValue)
5144

5245
const t = subscription
5346
subscription = source$.subscribe((value: O | typeof SUSPENSE) => {
54-
set(value === SUSPENSE ? gV : value)
47+
if (value !== SUSPENSE) set(value)
48+
else setState(gV as any)
5549
}, onError)
5650
t.unsubscribe()
5751

0 commit comments

Comments
 (0)