Skip to content

Commit

Permalink
fix: avoid calling functions emitted by observables (#132)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robintown authored Jul 27, 2024
1 parent 2fe24e9 commit 715a4e1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/observable-hooks/src/use-observable-eager-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function useObservableEagerState<TState>(
if (isAsyncEmissionRef.current) {
// ignore synchronous value
// prevent initial re-rendering
setState(value);
setState(() => value);
} else {
secondInitialValue = value;
}
Expand All @@ -85,7 +85,7 @@ export function useObservableEagerState<TState>(
if (!isAsyncEmissionRef.current) {
// fix #86 where sync emission may happen before useEffect
if (secondInitialValue !== state) {
setState(secondInitialValue);
setState(() => secondInitialValue);
}
}

Expand Down

0 comments on commit 715a4e1

Please sign in to comment.