• Custom React hook that triggers a callback when the observable property changes.

    This hook compares the current value of the observable property with its previous value. If they differ, it invokes the provided observer function with the current and previous values.

    Example

    const MyComponent = () => {
    const [count, setCount] = useState(0);

    useChange((newCount, oldCount) => {
    console.log(`Count changed from ${oldCount} to ${newCount}`);
    }, count);

    return (
    <button onClick={() => setCount(count + 1)}>
    Increment
    </button>
    );
    };

    Type Parameters

    • T

    Parameters

    • observer: ((value, prev) => void)

      Callback function to be invoked when the observable changes.

        • (value, prev): void
        • Parameters

          • value: T
          • prev: T

          Returns void

    • observable: T

      The observable value to be monitored for changes.

    Returns void