use-did-update

Calls given function in useEffect when value changes, but not when the component mounts

Import

Usage

use-did-update hook works the same way as useEffect but it is not called when component is mounted:

import { useDidUpdate } from '@mantine/hooks';

function Demo() {
  useDidUpdate(
    () => console.log("Won't be called when mounted"),
    [dependency1, dependency2]
  );
}

Definition

function useDidUpdate(fn: EffectCallback, dependencies?: any[]): void;