Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 575 Bytes

useDeepCompareEffect.md

File metadata and controls

30 lines (22 loc) · 575 Bytes

useDeepCompareEffect

A modified useEffect hook that is using deep comparison on its dependencies instead of reference equality.

Usage

import {useCounter, useDeepCompareEffect} from 'react-use';

const Demo = () => {
  const [count, {inc: inc}] = useCounter(0);
  const options = { step: 2 };

  useDeepCompareEffect(() => {
    inc(options.step)
  }, [options]);

  return (
    <div>
      <p>useDeepCompareEffect: {count}</p>
    </div>
  );
};

Reference

useDeepCompareEffect(effect: () => void | (() => void | undefined), deps: any[]);