Skip to content

Commit 715a4e1

Browse files
authored
fix: avoid calling functions emitted by observables (#132)
This fixes #131 at least for the case of useObservableEagerState. Looking at the code, it seems reasonable to expect that useObservableState and possibly other hooks suffer from the same issue. Those fixes would be more involved, though.
1 parent 2fe24e9 commit 715a4e1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/observable-hooks/src/use-observable-eager-state.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function useObservableEagerState<TState>(
6767
if (isAsyncEmissionRef.current) {
6868
// ignore synchronous value
6969
// prevent initial re-rendering
70-
setState(value);
70+
setState(() => value);
7171
} else {
7272
secondInitialValue = value;
7373
}
@@ -85,7 +85,7 @@ export function useObservableEagerState<TState>(
8585
if (!isAsyncEmissionRef.current) {
8686
// fix #86 where sync emission may happen before useEffect
8787
if (secondInitialValue !== state) {
88-
setState(secondInitialValue);
88+
setState(() => secondInitialValue);
8989
}
9090
}
9191

0 commit comments

Comments
 (0)