Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 573 Bytes

useDeepCompareEffect.md

File metadata and controls

30 lines (22 loc) · 573 Bytes

useDeepCompareEffect

一个修改的 useEffect 钩子,它使用对其依赖项的深度比较而不是引用的相等性。

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[]);