Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

use-shallow-effect

achmurali18MIT1.0.0TypeScript support: included

useEffect with shallow comparison for better performance.

shallow-compare, shallow-equal, useEffect, compare, performance

readme

use-shallow-effect

useEffect with shallow comparison. Additionaly, a shallow comparison function.

Description

Optimising useEffect hook with a shallow comparison of it's dependency list, providing better performance than deep-comparison or stock useEffect.

Features

  • useShallowEffect.
  • shallow comparison function.
  • Super Light and Fast.
  • Thoroughly tested.

Installation

npm install use-shallow-effect

Usage

using useShallowEffect -

import { useShallowEffect } from 'useShallowCompare';

useShallowEffect(() => {
    //side-effects generally used, similar to useEffect
}, dependency_list);

using the shallow comparison function -

import shallowCompare from 'useShallowCompare';

console.log(shallowCompare(a,b));//returns boolean

Shallow Comparison in words -

  • Object.is comparison between primitive types.
  • For other objects, iterate through their keys and comparing their values with ===

Currently supporting - primitive types, arrays, objects, map, set, date.