Skip to content

Files

Latest commit

c4911e6 Β· Dec 27, 2019

History

History
30 lines (22 loc) Β· 601 Bytes

useShallowCompareEffect.md

File metadata and controls

30 lines (22 loc) Β· 601 Bytes

useShallowCompareEffect

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

Usage

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

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

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

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

Reference

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