Skip to content

Commit

Permalink
Fix bug in useRerenderOnChange
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Sep 14, 2023
1 parent 48ebc37 commit 9ea5ac4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/tools/StatefulObservable/hooks/useRerenderOnChange.ts
Expand Up @@ -2,7 +2,6 @@ import { useObservable } from "./useObservable";
import { useState } from "react";
import type { StatefulObservable } from "../StatefulObservable";


/**
* Equivalent of https://docs.evt.land/api/react-hooks
* */
Expand All @@ -13,7 +12,11 @@ export function useRerenderOnChange($: StatefulObservable<unknown>): void {

useObservable(
({ registerSubscription }) => {
const subscription = $.subscribe(current => setCurrent(() => current));
const next = (current: unknown) => setCurrent(() => current);

next($.current);
const subscription = $.subscribe(next);

registerSubscription(subscription);
},
[$]
Expand Down

0 comments on commit 9ea5ac4

Please sign in to comment.