useHasChanged

A custom React hook that detects if a value has changed using deep comparison. Returns true when the value changes from the previous render, false otherwise.

Installation

import { useHasChanged } from 'uxp/components';

Signature

function useHasChanged(value: T): boolean

Examples

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

  return (
    <div>
      <p>Count: {count}</p>
      <p>Has changed: {hasCountChanged.toString()}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
};

Last updated